Skip to content

Commit

Permalink
implemented mnist using DNN
Browse files Browse the repository at this point in the history
  • Loading branch information
LordSomen committed Oct 11, 2018
1 parent 1aade63 commit 2cacb6a
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions AAN/arti_neural_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,38 @@
y_pred = per_clf.predict([[2,0.5]])
print(y_pred)


#%%
import tensorflow as tf

(X_train , Y_train) , (X_test,Y_test) = tf.keras.datasets.mnist.load_data()
print(X_train.shape,X_test.shape)
X_train = X_train.astype(np.float32).reshape(-1,28*28)/255.0
X_test = X_test.astype(np.float32).reshape(-1,28*28)/255.0
Y_train = Y_train.astype(np.int32)
Y_test = Y_test.astype(np.int32)
print(X_train.shape,X_test.shape)
X_valid , X_train = X_train[:5000],X_train[5000:]
Y_valid , Y_train = Y_train[:5000],Y_train[5000:]

print(X_train)

#%%
feature_cols = [tf.feature_column.numeric_column(
"X",shape=[28*28])]
dnn_clf = tf.estimator.DNNClassifier(hidden_units=
[300,100],n_classes = 10,feature_columns = feature_cols)

input_fn = tf.estimator.inputs.numpy_input_fn(
x = {"X":X_train},y=Y_train,num_epochs=40,
batch_size=50, shuffle = True
)
dnn_clf.train(input_fn=input_fn)

#%%
test_input_fn = tf.estimator.inputs.numpy_input_fn(
x={"X":X_test},y=Y_test,shuffle=False
)
eval_results = dnn_clf.evaluate(input_fn=test_input_fn)

print(eval_results)

0 comments on commit 2cacb6a

Please sign in to comment.