728x90
반응형

파이썬 73

[딥러닝] 사용자 데이터로 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..

[딥러닝] 필터 역할 살펴보기(다양한 이미지 출력)

선명한 이미지 추출하기 import numpy as np import cv2 import matplotlib.pyplot as plt image_color=cv2.imread('../images/cat.jpg') print('image_color.shape =',image_color.shape) image=cv2.cvtColor(image_color,cv2.COLOR_BGR2GRAY) print('image.shape =',image.shape) filter=np.array([ [-1,-1,-1], [-1,9,-1], [-1,-1,-1] ]) image_pad=np.pad(image,((5,5),(5,5))) print('image_pad.shape =', image_pad.shape) convoluti..

[딥러닝] 딥러닝 목표값 변경, 은닉층 늘리기, 학습 후 모델 내보내기, 모델 불러와 예측하기

딥러닝 목표값 형식을 2진수에서 10진수로 변경 _7seg_data.py import numpy as np np.set_printoptions(precision=4, suppress=True) X=np.array([ [ 1, 1, 1, 1, 1, 1, 0 ], # 0 [ 0, 1, 1, 0, 0, 0, 0 ], # 1 [ 1, 1, 0, 1, 1, 0, 0 ], # 2 [ 1, 1, 1, 1, 0, 0, 1 ], # 3 [ 0, 1, 1, 0, 0, 1, 1 ], # 4 [ 1, 0, 1, 1, 0, 1, 1 ], # 5 [ 0, 0, 1, 1, 1, 1, 1 ], # 6 [ 1, 1, 1, 0, 0, 0, 0 ], # 7 [ 1, 1, 1, 1, 1, 1, 1 ], # 8 [ 1, 1, 1, 0, 0,..

[딥러닝] 딥러닝 출력층에 linear 함수 적용해보기

linear 함수는 출력단의 값을 그대로 내보내는 함수로 linear 함수를 적용하여 학습을 수행할 경우 선형회귀라고 합니다. import tensorflow as tf from _7seg_data import X, YT model=tf.keras.Sequential([ tf.keras.Input(shape=(7,)), tf.keras.layers.Dense(16, activation='relu'), tf.keras.layers.Dense(4, activation='linear') ]) model.compile(optimizer='adam',loss='mse') model.fit(X,YT,epochs=10000) Y=model.predict(X) print(Y)

[딥러닝] 딥러닝 국소해의 문제 해결해보기

인공신경망 학습이 제대로 되지 않는 경우 국소해 문제로 발생합니다. 국소해 문제가 발생할 경우엔 재학습을 수행해보거나 은닉층의 노드수를 변경해봅니다. import tensorflow as tf from _7seg_data import X, YT model=tf.keras.Sequential([ tf.keras.Input(shape=(7,)), tf.keras.layers.Dense(16, activation='relu'), tf.keras.layers.Dense(4, activation='sigmoid') ]) model.compile(optimizer='adam',loss='mse') model.fit(X,YT,epochs=10000) Y=model.predict(X) print(Y)

[딥러닝] 딥러닝 활성화 함수 적용하기

딥러닝 7 공식 적용하기 from math import exp x1,x2=0.05,0.10 w1,w2=0.15,0.20 w3,w4=0.25,0.30 b1,b2=0.35,0.35 w5,w6=0.40,0.45 w7,w8=0.50,0.55 b3,b4=0.60,0.60 y1T,y2T=0.01,0.99 lr=0.01 EPOCH=1000 for epoch in range(EPOCH): h1=x1*w1+x2*w2+1*b1 h2=x1*w3+x2*w4+1*b2 # ReLU feed forward h1=h1 if h1>0 else 0 h2=h2 if h2>0 else 0 y1=h1*w5+h2*w6+1*b3 y2=h1*w7+h2*w8+1*b4 # sigmoid feed forward y1=1/(1+exp(-y1)) y2=1..

[딥러닝] 딥러닝 학습 과정 살펴보기(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,..

[딥러닝] 딥러닝 인공 신경망 텐서플로(tensorflow)로 구현하기 연습문제

연습문제 1. 텐서플로를 사용하여 2입력 1출력 인공 신경망 구현하기 import tensorflow as tf import numpy as np X=np.array([[2,3]]) # 입력데이터 YT=np.array([[27]]) # 목표데이터(라벨) W=np.array([[3],[4]]) # 가중치 B=np.array([1]) # 편향 model=tf.keras.Sequential([ tf.keras.Input(shape=(2,)), # 입력층 노드의 개수를 1로 설정합니다. tf.keras.layers.Dense(1) # 출력층 노드의 개수를 1로 설정합니다. ]) # 신경망 모양 결정(W,B 내부적 준비) model.layers[0].set_weights([W,B]) model.compile(op..

[딥러닝] 딥러닝 인공 신경망 텐서플로(tensorflow)로 구현하기

* 텐서플로우, 오픈cv, matplotlib, numpy 설치가 필요합니다. 1. 1입력 1출력 인공 신경망 구현하기 import tensorflow as tf import numpy as np X=np.array([[2]]) # 입력데이터(가로가 2개) YT=np.array([[10]]) # 목표데이터(라벨) W=np.array([[3]]) # 가중치 B=np.array([1]) # 편향 model=tf.keras.Sequential([ tf.keras.Input(shape=(1,)), # 입력층 노드의 개수를 1로 설정합니다. tf.keras.layers.Dense(1) # 출력층 노드의 개수를 1로 설정합니다. ]) # 신경망 모양 결정(W,B 내부적 준비) model.layers[0].set_w..

[딥러닝] 딥러닝 인공 신경망 구현하기 연습문제 2

연습문제 1. 2입력 2은닉 2출력 인공신경망 x1,x2=0.05,0.10 w1,w2=0.15,0.20 w3,w4=0.25,0.30 b1,b2=0.35,0.35 w5,w6=0.40,0.45 w7,w8=0.50,0.55 b3,b4=0.60,0.60 y1T,y2T=0.01,0.99 lr=0.01 for epoch in range(2000): h1=x1*w1+x2*w2+1*b1 h2=x1*w3+x2*w4+1*b2 y1=h1*w5+h2*w6+1*b3 y2=h1*w7+h2*w8+1*b4 E=((y1-y1T)**2+(y2-y2T)**2)/2 y1E=y1-y1T y2E=y2-y2T w5E=y1E*h1 w6E=y1E*h2 w7E=y2E*h1 w8E=y2E*h2 b3E=y1E*1 b4E=y2E*1 h1E=y1E*w5+y..

728x90
반응형