반응형
Notice
Recent Posts
Recent Comments
Link
관리 메뉴

bro's coding

keras.mnist(중간층X) 본문

[AI]/python.keras

keras.mnist(중간층X)

givemebro 2020. 5. 13. 17:33
반응형
import keras
from keras.datasets import mnist

 

(X_train,y_train),(X_test,y_test)=mnist.load_data()



# 데이터 전처리
X_train=X_train.reshape(-1,28*28)/255.
X_test=X_test.reshape(-1,28*28)/255.
y_train=np.eye(10)[y_train]
y_test=np.eye(10)[y_test]



model=Sequential()
model.add(Dense(1,input_shape=(28,28),activation='sigmoid'))
from keras.optimizers import SGD
model.compile(loss='binary_crossentropy',optimizer=SGD(lr=0.1),metrics=['acc'])
# metrics=['acc'] : 화면 출력 할 때 정확도도 출력해라!(history에서 확인 가능)


 

 

from keras.models import Sequential
from keras.layers import Dense
from keras.optimizers import SGD,RMSprop,Adagrad

 

 

model=Sequential()
model.add(Dense(10,input_shape=(784,),activation='softmax'))
model.compile(loss='categorical_crossentropy',optimizer='rmsprop',metrics=['acc'])
model.fit(X_train,y_train,epochs=100)

 

 

pred_y=model.predict(X_test)

 

ws=model.get_weights()
ws[0]
array([[ 0.00650029,  0.07752211,  0.04841069, ..., -0.07710665,
        -0.00478213,  0.01459844],
       [-0.06074725, -0.00682037,  0.08317574, ...,  0.07438696,
         0.01124036,  0.02353244],
       [ 0.06043867, -0.04523697, -0.06475241, ...,  0.08567973,
         0.07345223,  0.08374571],
       ...,
       [ 0.03114741, -0.02464399, -0.05945008, ..., -0.07596971,
        -0.06711061,  0.01014983],
       [-0.06079032, -0.04003002,  0.00654893, ..., -0.08453656,
         0.04763127,  0.06974082],
       [ 0.01717632, -0.06559615, -0.066451  , ...,  0.07759722,
        -0.08055964, -0.02816157]], dtype=float32)

 

 

plt.figure(figsize=[10,10])
for i in range(10):
    plt.subplot(2,5,i+1)
    plt.title(i)
    plt.imshow(ws[0][:,i].reshape(-1,28))

반응형

'[AI] > python.keras' 카테고리의 다른 글

keras.layers.Flatten  (0) 2020.05.13
keras.save  (0) 2020.05.13
keras.score  (0) 2020.05.13
keras.mnist(중간층)  (0) 2020.05.13
keras.mnist  (0) 2020.05.13
keras.iris(분류)  (0) 2020.05.13
keras.basic(분류)  (0) 2020.05.13
keras.iris(예측 )  (0) 2020.05.13
Comments