728x90
반응형

인공신경망학습 31

[딥러닝] 딥러닝 활용하기(패션 MNIST 데이터 셋 학습하기)

패션 MNIST 데이터 셋은 10개의 범주 (category)와 70,000개의 흑백 이미지로 구성되어 있습니다. import tensorflow as tf mnist = tf.keras.datasets.fashion_mnist (X, YT), (x, yt) = mnist.load_data() #60000개의 학습데이터, 10000개의 검증데이터 X, x = X/255, x/255 # 60000x28x28, 10000x28x28 X, x = X.reshape((60000,784)), x.reshape((10000,784)) model = tf.keras.Sequential([ tf.keras.Input(shape=(784,)), tf.keras.layers.Dense(128, activation='rel..

[딥러닝] 딥러닝 활용하기(MNIST 선형회귀)

MNIST 선형 회귀 import tensorflow as tf mnist = tf.keras.datasets.mnist (X, YT), (x, yt) = mnist.load_data() #60000개의 학습데이터, 10000개의 검증데이터 X, x = X/255, x/255 # 60000x28x28, 10000x28x28 X, x = X.reshape((60000,784)), x.reshape((10000,784)) model = tf.keras.Sequential([ tf.keras.Input(shape=(784,)), tf.keras.layers.Dense(512, activation='relu'), tf.keras.layers.Dense(256, activation='relu'), # 은닉화 tf..

[딥러닝] 딥러닝 활용하기(손글씨 숫자 데이터 인식)

MNIST라고 하는 손글씨 숫자 데이터를 입력받아 학습시켜봅니다. import tensorflow as tf mnist=tf.keras.datasets.mnist (X,YT),(x,yt)=mnist.load_data() #60000개의 학습데이터, 10000개의 검증데이터 X,x=X/255, x/255 # 60000x28x28, 10000x28x28 X,x=X.reshape((60000,784)), x.reshape((10000,784)) model = tf.keras.Sequential([ tf.keras.Input(shape=(784)), tf.keras.layers.Dense(128,activation='relu'), tf.keras.layers.Dense(10,activation='softmax'..

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

딥러닝 목표값 형식을 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)

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

딥러닝 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..

[딥러닝] 딥러닝 활성화 함수(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..

[딥러닝] 딥러닝 인공 신경망 텐서플로(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
반응형