728x90
반응형

딥러닝학습 11

[딥러닝] 사용자 데이터로 CNN 학습하기- 6. 시험 데이터로 확인해보기

6. 시험 데이터로 확인해보기 _04_cnn_training_5.py from _04_cnn_training_3 import * from tensorflow.keras.models import load_model import matplotlib.pyplot as plt model1=load_model('model.h5') # Model predictions for the testing dataset y_test_predict=model1.predict(x_test) print(y_test_predict.shape, y_test_predict[0]) y_test_predict=np.argmax(x_test_predict, axis=1) print(y_test_predict.shape, y_test_pred..

[딥러닝] 사용자 데이터로 CNN 학습하기- 5. 인공신경망 학습시키기

5. 인공신경망 학습시키기 _04_cnn_training_4.py from _04_cnn_training_3 import * import tensorflow as tf model=tf.keras.Sequential([ # donkey car CNN tf.keras.layers.Conv2D(24,(5,5), strides=(2,2), padding='same', activation='relu', input_shape=x_train.shape[1:]), tf.keras.layers.Dropout(0.2), tf.keras.layers.Conv2D(32,(5,5), strides=(2,2), padding='same', activation='relu'), tf.keras.layers.Dropout(0.2), ..

[딥러닝] 사용자 데이터로 CNN 학습하기- 4. 훈련, 검증, 시험 데이터 분리하기

4. 훈련, 검증, 시험 데이터 분리하기. 훈련 데이터 80%, 검증 데이터 10%, 시험 데이터 10%로 임의로 분리합니다. 훈련 데이터는 인공신경망 학습에 사용 검증 데이터는 학습 도중에 검증용으로 사용 시험 데이터는 학습이 끝난 후에 사용합니다. _04_cnn_training_3.py from _04_cnn_training_1 import * from tensorflow.keras.utils import to_categorical from sklearn.model_selection import train_test_split tensors=tensors.astype('float32')/255 targets=to_categorical(targets, 4) x_train, x_test, y_train, ..

[딥러닝] 사용자 데이터로 CNN 학습하기- 3. 수집한 이미지 출력해보기

3. 수집한 이미지 출력해보기 _04_cnn_training_2.py from _04_cnn_training_1 import * import cv2 import matplotlib.pyplot as plt # Name list names=['_0_forward','_1_right','_2_left','_3_stop'] def display_images(img_path, ax): img=cv2.imread(os.path.join(dirname,img_path)) ax.imshow(cv2.cvtColor(img,cv2.COLOR_BGR2RGB)) fig=plt.figure(figsize=(10,3)) for i in range(4): ax=fig.add_subplot(1,4,i+1,xticks=[], yti..

[딥러닝] 사용자 데이터로 CNN 학습하기- 2. 수집한 데이터 불러오기

2. 수집한 데이터 불러오기 수집한 데이터를 읽어와서 인공 신경망에서 사용할 수 있는 텐서로 변경합니다. 텐서는 3차원 이상의 행렬을 의미하며 프로그래밍 언어 관점에서는 3차원 이상의 배열이 됩니다. 04_cnn_training_1.py from tensorflow.keras.preprocessing import image as keras_image import os import numpy as np from tqdm import tqdm from PIL import ImageFile import pandas as pd dirname="data.1695035538.287210" def image_to_tensor(img_path): img=keras_image.load_img( os.path.join(d..

[딥러닝] 사용자 데이터로 CNN 학습하기- 1. 라벨링하기

1. 라벨링하기 수집한 이미지 데이터에 라벨링 작업을 합니다. _03_data_labelling.py import os import csv dataDir='data.1695035538.287210' # 데이터 저장 디렉토리 print(os.getcwd()) # 현재 디렉터리 어딘지 확인(cwd=current working directory) os.chdir(dataDir) # 디렉터리 이동(change directory) roadDirs=os.listdir() # 현재 디렉터리 확인 print(roadDirs) f_csv=open('0_road_labels.csv','w',newline='') wr=csv.writer(f_csv) wr.writerow(["file","label","labelNames"]..

[딥러닝] 알렉스넷 바탕으로 신경망 구성하기, 배치 정규화, 드롭아웃 적용하기

알렉스넷 아키텍처 신경망 구성하기 import tensorflow as tf import numpy as np X=np.random.randint(0,256,(5000,227,227,3)) YT=np.random.randint(0,1000,(5000,)) x=np.random.randint(0,256,(1000,227,227,3)) yt=np.random.randint(0,1000,(1000,)) model = tf.keras.Sequential([ tf.keras.layers.InputLayer(input_shape=(227,227,3)), tf.keras.layers.Conv2D(96,(11,11),(4,4),activation='relu'), tf.keras.layers.MaxPooling2D((3..

[딥러닝] 딥러닝 활용하기(임의 흑백, 컬러 이미지 데이터 셋 학습)

임의 흑백 이미지 데이터 셋 생성하기 import tensorflow as tf import numpy as np X=np.random.randint(0,256,(60000,28,28)) YT=np.random.randint(0,10,(60000,)) x=np.random.randint(0,256,(10000,28,28)) yt=np.random.randint(0,10,(10000,)) print(X.shape, YT.shape, x.shape, yt.shape) import matplotlib.pyplot as plt plt.imshow(X[0]) plt.show() print(YT[0]) 임의 흑백 이미지 데이터 셋 학습하기 import tensorflow as tf import numpy as np..

[딥러닝] 딥러닝 활성화 함수(sigmoid, ReLU, 계단 함수)

1. sigmoid 함수 그려보기(계단 함수, 역전파) import numpy as np def sigmoid(x): return 1/(1+np.exp(-x)) # x=np.random.uniform(-10,10,1000) x=np.random.uniform(-10,100,10000) y=sigmoid(x) import matplotlib.pyplot as plt plt.plot(x,y,'r.') plt.show() 2. ReLU 함수 그려보기 import numpy as np def ReLU(x): return x*(x>0) x=np.random.uniform(-10,10,1000) y=ReLU(x) import matplotlib.pyplot as plt plt.plot(x,y,'g.') plt.sh..

[딥러닝] 딥러닝 학습 과정 살펴보기(numpy, matplotlib 라이브러리)

numpy, matplotlib 라이브러리를 이용하여 딥러닝 학습 예제 1. w, b, E의 관계 살펴보기 import numpy as np # numpy 행렬 import matplotlib.pyplot as plt # matplotlib 그래프로 표현해줌 fig = plt.figure(figsize=(8,8)) ax = fig.add_subplot(projection='3d') ax.set_title("wbE",size=20) ax.set_xlabel("w", size=14) ax.set_xlabel("b", size=14) ax.set_xlabel("E", size=14) x=2 yT=10 w=np.random.uniform(-200,200,10000) b=np.random.uniform(-200,..

728x90
반응형