인공지능 22

tensor flow hub -> finetune 사용하기

# Day_34_01_tfhub_finetune.py import tensorflow as tf import pandas as pd import numpy as np import matplotlib.pyplot as plt import PIL.Image as Image import tensorflow_hub as hub from tensorflow.keras.preprocessing.image import ImageDataGenerator # Fine-tuning 이란 # 남이 만들어 놓은 모듈을 내가 조금만 다듬어서 사용하겠다 # trainable=True to hub.KerasLayer이걸 써서 # resnet_50 모델을 사용해서 꽃 데이터셋에 대해 학습하고 랜덤으로 뽑은 32장의 이미지에 대해 예..

인공지능 2020.12.20

tensor flow hub 사용하기.

# Day_33_02_tfhub.py import tensorflow as tf import pandas as pd import numpy as np import matplotlib.pyplot as plt import PIL.Image as Image import tensorflow_hub as hub from tensorflow.keras.preprocessing.image import ImageDataGenerator # 오늘의 핵심 -> 안되는 컴터는 껏다 켜기 -> 접근 권한? 때문일 수도 있음 # mobilenet_v2 사용 방법 def get_image_classifier(): url = 'https://tfhub.dev/google/tf2-preview/mobilenet_v2/classif..

인공지능 2020.12.20

Callback ( check_point와 Earlystopping)

# Day_32_02_callback.py import tensorflow as tf import pandas as pd import numpy as np from sklearn import preprocessing, model_selection # 자동차 데이터에 대해 80%로 학습하고 20%에 대해 정확도를 구하세요 checkpoint 쓸꺼임 # dense : LabelBinarizer : 피처의 개수가 훨씬 많아짐 # sparse: LableEncoder : 그냥 변환 def get_cars_sparse(): names = ['buying', 'maint', 'doors', 'persons', 'lug_boot', 'safety', 'acc'] cars = pd.read_csv('data/car.d..

인공지능/RNN 2020.12.15

pop corn DBset으로 Baseline, rnn, cnn, cnn-tf, word2vec, nltk 구성하기

이번 코드는 상당히 여러가지 요소들도 많고 기법들도 많이 들어가 있으니 주석을 잘 보시길 바랍니다. # Day_29_01_popcorn.py import tensorflow as tf import pandas as pd import numpy as np import matplotlib.pyplot as plt import gensim import nltk from sklearn import model_selection, feature_extraction, linear_model import re # popcorn_models # labeled = train set # sample = 데이터를 만들어야하는 형태 # testData = test set (id와 리뷰만 있음) # unlabeld = train..

인공지능/RNN 2020.12.15

Keras CNN functional로 글써보기

# Day_28_02_chosun.py import tensorflow as tf import numpy as np import re # 파일 다운로드 # url = 'http://bit.ly/2Mc3SOV' # file_path = tf.keras.utils.get_file( # 'chosun.txt', url, cache_dir='.', cache_subdir='data') # print(file_path) # str 정리 한글처리부분 ( 불용어 ) def clean_str(string): string = re.sub(r"[^가-힣0-9]", " ", string) # string = re.sub(r",", " , ", string) # string = re.sub(r"!", " ! ", string..

인공지능/CNN 2020.12.10

Keras functional

# Day_27_01_functional.py import tensorflow as tf import numpy as np # 지금까지는 sequential 이였다면 지금부터는 functional # AND 데이터셋에 대해 정확도를 계산하는 모델을 만들 것임. def and_sequential(): data = [[0, 0, 0], [0, 1, 0], [1, 0, 0], [1, 1, 1]] data = np.int32(data) x = data[:, :-1] y = data[:, -1:] print(x.shape, y.shape) # (4, 2) (4, 1) model = tf.keras.Sequential() model.add(tf.keras.layers.Input(shape=[2])) model.ad..

인공지능 2020.12.10

딥러닝 학습할 때 예측결과를 높이는 여러가지 방법들

# Day_26_01_PokerCompetition.py # 99_Poker.py import tensorflow as tf import numpy as np import pandas as pd from sklearn import preprocessing, model_selection from operator import itemgetter # poker-hand 데이터셋을 추가해주면 동작 가능 # acc 올리기 # 1번. 스케일링 def apply_scaling(x): return preprocessing.scale(x) # 2번. 원핫 벡터 def apply_onehot(x): # suit : 4가지 * 5 = 20 # card : 13가지 * 5 = 65 enc = preprocessing.Labe..

인공지능 2020.12.09

이미지 증식과 분석, 사전학습된 것 적용시키기 (전이 학습)

# Day_25_01_DogsAndCats.py import tensorflow as tf import numpy as np import os import time import pickle import matplotlib.pyplot as plt from tensorflow.keras import optimizers from tensorflow.keras.preprocessing.image import ImageDataGenerator as IDG # 베이스 라인 만들 것임 # 이미지 증식 후 분석 # slim 에서 본거 같이 사전학습된 것으로 우리꺼 예측해볼 것 (전이 학습) def get_model_name(version): filename = 'dogcat_small_{}.h5'.format(ver..

인공지능/CNN 2020.12.09