본문 바로가기

ALL257

딥러니 텐서플로우 CNN을 이용하여, CIFAR-10 이미지 분류하기, 데이트셋이 이미 넘파이라면? CNN을 이용하여, CIFAR-10 이미지 분류하기¶ STEP 0: 데이터셋 설명¶ CIFAR-10 is a dataset that consists of several images divided into the following 10 classes: Airplanes Cars Birds Cats Deer Dogs Frogs Horses Ships Trucks The dataset stands for the Canadian Institute For Advanced Research (CIFAR) CIFAR-10 is widely used for machine learning and computer vision applications. The dataset consists of 60,000 32x32 colo.. 2023. 1. 2.
파이썬 원본 폴더에 이미지 파일 여러개를 일정비율로 나눠서, 랜덤으로 파일의 순서를 바꾼다음, 새로운폴더를 생성하여 넣는 방법 환경 : 리눅스 ( 윈도우도 됨) PetImages 라는 원본폴더 안에 Cat 폴더 안에는 고양이 사진이 12500장 Dog 폴더 안에는 개사진이 12500장 있다고 해보자 새로운 cats-v-dogs 라는 폴더를 생성하고 그안에 testing 폴더, training 폴더를 생성 testing 안에 cats, dogs training 안에 cats, dogs 폴더를 생성한다음 원본에 있는 사진을 일정 비율로 나눠서 (예를들면 9대1로 나누면 11250장, 1250장) testing 안에 cats 폴더에 1250장 testing 안에 dogs 폴더에 1250장 training 안에 cats 폴더에 11250장 training 안에 dogs 폴더에 11250장 이렇게 옮길것이다. 1.필요한 라이브러리를 임포.. 2022. 12. 30.
딥러닝 텐서플로우 이미지 증강 예시 Image Augmentation¶ Cats v Dogs 로 다음처럼 모델링 하고, 학습시켜본다. 4 convolutional layers with 32, 64, 128 and 128 convolutions train for 100 epochs 데이터 제너레이터를 통해 이미지를 증강한다.¶ train_datagen = ImageDataGenerator( rotation_range=40, width_shift_range=0.2, height_shift_range=0.2, shear_range=0.2, zoom_range=0.2, horizontal_flip=True, fill_mode='nearest') rotation_range is a value in degrees (0–180), a range wit.. 2022. 12. 30.
딥러닝 텐서플로우 개와 고양이 분류하는 Neural Network 만들기 Using more sophisticated images with Convolutional Neural Networks¶I실생활의 이미지는 모양도 다르고, 비율도 다르고, 색깔도 다양하다. 이러한 것들을 분류하는 CNN을 만들어 본다. Cats and Dogs 이미지 이용 개와 고양이 분류하는 Neural Network 만들기 Evaluate the Training and Validation accuracy Explore the Example Data¶ /tmp 컬럼에, 2000개의 이미지를 다운로드 받아서 저장한다. NOTE: 2,000 개의 이미지는 캐글에서 가져왔다. "Dogs vs. Cats" dataset 원래는 25,000 개의 이미지 이지만, 실습용으로 추렸음. In [ ]: In [2]: .. 2022. 12. 30.
딥러닝 텐서플로우 CNN 구조, pooling, 파이썬으로 압축파일 풀기, JPG나PNG 같은 이미지파일을 학습 데이터로 만드는 방법, 파이썬 각 폴더에 저장되어 있는 사진파일이름들 출력 1. CNN구조 결론부터 말하면 : 사진의 특징을 잡아서 압축하는 개념 이미지는 행과 열로 이루어져있다 예시 (28, 28) 그래서 Gray(1차원) 이미지 같은경우는 Flatton()만 사용해서 학습을 시키면 되지만. 컬러이미지는 R, G ,B 3장으로 이루어진것과 같다.(3차원 이라는것) (28, 28, 3) 그렇기에 변환 과정을 거쳐야 한다. 과정은 kernel 로 image에 stride 만큼 feature map으로 만들어 (Convolution + ReLu) (변환) MAX or Average 로 stride만큼 Pooling (Downsampling) 해서 Flattening 하는것 (압축) 2. 파이썬으로 압축파일 푸는방법 import zipfile file = zipfile.ZipFile.. 2022. 12. 30.
딥러닝 텐서플로우 CNN 인간,말 분류, 파이썬으로 압축풀기, 이미지파일을 넘파이 어레이로가져오기 이미지 파일 다운로드. 말, 인간 분류하기 위한 사진 파일 다운로드 하기 In [1]: !wget --no-check-certificate \ # !wget 리눅스 주피터노트북에서 웹파일을 가져오는 명령어 https://storage.googleapis.com/laurencemoroney-blog.appspot.com/horse-or-human.zip \ -O /tmp/horse-or-human.zip # -O 여기에 다운로드 받아라. --2022-12-30 02:05:48-- https://storage.googleapis.com/laurencemoroney-blog.appspot.com/horse-or-human.zip Resolving storage.googleapis.com (storage.goo.. 2022. 12. 30.
딥러닝 텐서플로우 CNN의 기본개념 kenel == filter == feature detector 라고도 함 https://poloclub.github.io/cnn-explainer/ 풀링 stride = 2 == (2행2열) 풀링이란 예를들어 4*4 를 2*2로 줄이는방법 relu == 0밑은 무조건 0으로 바꿈, 양수는 그대로 쓴다 Fully Connected == ANN (같은말) 이렇게 하는 이유는 1.컴퓨팅 자원을 적게 쓰기 위함 2.특징을 살린다(예를들면 위치정보 같은것) 2022. 12. 29.
딥러닝 텐서플로우 레이블링된 y값을 tf.keras.utils.to_categorical 함수 이용해서 원핫인코딩으로 바꾸기, 분류의 문제에서, loss 함수를 categorical_crossentropy로 설정할때는 어떤상황일때? 1.레이블링된 y값을 tf.keras.utils.to_categorical 함수 이용해서 원핫인코딩으로 바꾸기 from keras.utils import to_categorical y_train [out] array([5, 0, 4, ..., 5, 6, 8], dtype=uint8) y_train = tf.keras.utils.to_categorical(y_train, num_classes = 10) [out] array([[0., 0., 0., ..., 0., 0., 0.], [1., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], ..., [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.],.. 2022. 12. 29.
딥러닝 텐서플로우 ANN 손글씨 숫자 예측, y_test가 카테고리컬 데이터라면, 원핫인코딩으로 나온 결과를 argmax를 이용하여 복원 MNIST 손글씨 숫자 예측¶ In [58]: 다음과 같은 ANN 을 만든다¶이미지파일(28X28픽셀)이 입력으로 들어오면, 아웃풋으로는 0~9 까지의 10개 숫자로 분류하는 인공지능! 사진은 2차원 데이터이므로, 우리는 ANN의 입력에, 사진의 픽셀값을 flattening 하여 입력을 줄 것이다. 따라서 입력레이어는 784개, 히든1은 512, 히든2는 512, 아웃풋은 10개의 신경망 구축. In [58]: In [58]: In [59]: import numpy as np import matplotlib.pyplot as plt import pandas as pd from PIL import Image %matplotlib inline In [60]: import tensorflow as tf fro.. 2022. 12. 29.
딥러닝 텐서플로우 모델을 저장하는방법, 모델중 네트워크와 웨이트를 따로 저장하고 불러오는 방법 Saving the architecture # ANN == 아티피셜 뉴럴 네트워크 # 전체 네트워크(build_model())와 웨이트(선==w==가중치)를 통으로 저장하고 불러오기 # 폴더구조로 저장. model.save('fashion_mnist_model') # 저장된 인공지능을 불러오는 코드. model2 = tf.keras.models.load_model('fashion_mnist_model') model2.evaluate(X_test, y_test) # 모델을, 파일 하나로 저장하는 방법 model.save('fashion_mnist_model.h5') # 파일을 불러오기 model3 = tf.keras.models.load_model('fashion_mnist_model.h5') model3.. 2022. 12. 29.
딥러닝 텐서플로우 이미지 10개로 분류 Saving architecture & Saving network weights, Dropout, validation_data, Flatten안쓰기 Image source: https://www.kaggle.com/ Stage 1: Installing dependencies¶ In [1]: # 코랩은 이미 깔려잇어 pass In [1]: Stage 2: Import dependencies for the project¶ In [2]: import numpy as np import tensorflow as tf from tensorflow.keras.datasets import fashion_mnist Stage 3: Dataset preprocessing¶ Loading the dataset¶ In [3]: (X_train,y_train),(X_test,y_test)= fashion_mnist.load_data() # 넘파이로 받아옴 // (X_tra.. 2022. 12. 29.
딥러닝 텐서플로우 Flatten()을 사용하지않는, validation_data 파라미터 split 과의 차이, Dropout이란 1. Flatten() 라이브러리 없이 이미지 평탄화 하는방법 예시) X_train.shape # 3차원 (60000, 28, 28) X_train = X_train.reshape(60000, 784) # 평탄화 // 2차원 마찬가지로 X_test도 reshape을 이용한다 . 모델링 예시) def build_model() : model = Sequential() model.add( Dense(128, 'relu', input_shape=(784, ) ) ) model.add( Dropout(0.2) ) # 학습할때 20프로의 선을 없애라는뜻 (이부분만) model.add( Dense(64, 'relu')) model.add( Dense(10, 'softmax')) model.compile('adam',.. 2022. 12. 29.