앎을 경계하기

다핏 42

<DAFIT> 10 Pytorch를 통한 Classification 입문 - 01 라이브러리 준비, 데이터 전처리

fashion MNIST 데이터셋 TF from tensorflow import keras keras.datasets.fashion_mnist(...) PyTorch from torchvision import datasets datasets.FashionMNIST('~/.pytorch/F_MNIST_data/',...) transform = transforms.Compose([ transforms.ToTensor(), transforms.Normalize(mean=0.5, std=0.5) ]) ToTensor() : 텐서로 변환해줌. 0~1로 변경 Normalize(mean=0.5, std=0.5) : -1 ~ 1 사이로 normalize함 grayscale이기 때문에 0.5로 해준다. 만약 3 colo..

<DAFIT> 09 OpenCV 연습하기(1) - 06 Edge Detection(1)

https://docs.opencv.org/3.4/d2/d2c/tutorial_sobel_derivatives.html OpenCV: Sobel Derivatives Prev Tutorial: Adding borders to your images Next Tutorial: Laplace Operator Goal In this tutorial you will learn how to: Use the OpenCV function Sobel() to calculate the derivatives from an image. Use the OpenCV function Scharr() to calculate a more accur docs.opencv.org 가장자리는 급격하게 값이 변하는 곳으로 표현할 수 있다. ..

<DAFIT> 07 OpenCV 다루기 첫걸음 - 07 영상 어파인 변환

import cv2 from google.colab.patches import cv2_imshow import numpy as np img_path = '/content/drive/My Drive/다핏문제/907/lena.jpg' 세 개의 꼭지점을 정해주면 getAffineTransform을 통해 이미지 변환을 할 수 있다. img = cv2.imread(img_path,1) height, width = img.shape[:2] controls = [] controls.append((0,0)) controls.append((0,height)) controls.append((width,0)) controls.append((width, height)) src = np.float32([list(co..

<DAFIT> 07 OpenCV 다루기 첫걸음 - 06 영상 크기 조절

이번에는 resizing 문제이다. import cv2 from google.colab.patches import cv2_imshow img_path = '/content/drive/My Drive/다핏문제/907/lena.jpg' img = cv2.imread(img_path,1) height, width = img.shape[:2] down_img = cv2.resize(img,(height//2,width//2)) cv2_imshow(down_img) up_img = cv2.resize(img, (height*2, width*2)) cv2_imshow(up_img) img_list = [] for i in range(100): img_list.append(cv2.resize(img,(he..

<DAFIT> 07 OpenCV 다루기 첫걸음 - 05 영상 뒤집기

이번에는 flip을 해보는 문제이다. import cv2 from google.colab.patches import cv2_imshow import numpy as np img_path = '/content/drive/My Drive/다핏문제/907/lena.jpg' flip함수는 사용하는 게 굉장히 쉽다. 1이면 좌우반전, 0이면 상하반전을 한다. img = cv2.imread(img_path,1) print('origin') cv2_imshow(img) v_img = cv2.flip(img, 1) print('\n\nvertical flip') cv2_imshow(v_img) h_img = cv2.flip(img, 0) print('\n\nhorizontal flip') cv2_imshow..

<DAFIT> 07 OpenCV 다루기 첫걸음 - 04 영상 회전

지난번 translation에 이어 이번에는 rotation을 해보는 문제이다. import cv2 import numpy as np from google.colab.patches import cv2_imshow img_path = '/content/drive/My Drive/다핏문제/907/lena.jpg' angle을 지정해서 cv2.getRotationMatrix2D()를 사용해서 이미지의 중심점, 회전할 각도, 이미지크기(scale)을 넣어서 matrix를 구성해서 warpAffine에 넣어주면 된다. img = cv2.imread(img_path,1) rows, cols = img.shape[:2] angle = 90.0 M = cv2.getRotationMatrix2D((cols/2..

<DAFIT> 07 OpenCV 다루기 첫걸음 - 03 영상 이동

사진을 이동시켜보는 문제이다. import cv2 import numpy as np from google.colab.patches import cv2_imshow img_path = '/content/drive/My Drive/다핏문제/907/lena.jpg' x축으로 50 ( 1, 0, 50 ), y축으로 50 ( 0, 1, 50 ) 이동해보자. img = cv2.imread(img_path,1) rows, cols = img.shape[:2] M = np.float32([[1,0,50],[0,1,50]]) img_result = cv2.warpAffine(img, M, (cols, rows)) cv2_imshow(img_result) 굉장히 쉽게 성공했다! http://www.dafit.m..

<DAFIT> 07 OpenCV 다루기 첫걸음 - 02 영상 읽기, 출력, 저장

이번에는 이미지의 채널을 변환하고 분리하고 병합하는 것이다. import cv2 as cv from google.colab.patches import cv2_imshow img_path = '/content/drive/My Drive/다핏문제/907/lena.jpg' * 채널 변환 # OpenCV의 삼원색 기본 순서는 BGR이다. img_bgr = cv.imread(img_path,1) img_rgb = cv.cvtColor(img_rgb, cv.COLOR_BGR2RGB) cv2_imshow(img_bgr) cv2_imshow(img_rgb) * 채널 분리 및 병합 b,g,r = cv.split(img_bgr) img_rbg = cv.merge((r,b,g)) cv2_imshow(img_rbg..

<DAFIT> 06 머신러닝을 통한 당뇨병 예측 - 07 Feature Importance

지금까지 풀었던 문제를 다시 한 번 정리해볼 수 있는 시간이다. from sklearn.tree import DecisionTreeClassifier from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import train_test_split import pandas as pd 지난 번 예측문제에서 사용했던 의사결정트리와 랜덤포레스트를 다시 한 번 사용한다. 데이터를 로드하고, data = pd.read_csv("/content/drive/My Drive/다핏문제/906/dataset_37_diabetes.csv") data 결측치 처리한다. presd = data.replace({'pres':0},..

<DAFIT> 06 머신러닝을 통한 당뇨병 예측 - 06 Random Forest를 이용한 당뇨병 예측

지난번엔 Decision Tree였다면 이번에는 Random Forest이다. 랜덤 포레스트는 앙상블 방법 중 하나로 여러개의 의사결정트리가 모여서 classification이나 regression 문제를 푼다. sklearn.ensemble 내 RandomForestClassifier를 제공하고있다. from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import train_test_split import pandas as pd data = pd.read_csv("/content/drive/My Drive/다핏문제/906/dataset_37_diabetes.csv") data #데이터 결측치 처리와 ..