-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDropoutSkeleton.py
More file actions
122 lines (100 loc) · 3.43 KB
/
Copy pathDropoutSkeleton.py
File metadata and controls
122 lines (100 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#https://github.com/rndbrtrnd/udacity-deep-learning/blob/master/3_regularization.ipynb
from __future__ import print_function
import numpy as np
import tensorflow as tf
from six.moves import cPickle as pickle
import matplotlib.pyplot as plt
pickle_file = 'notMNIST.pickle' #generated notMINST.pickle file-> https://github.com/StryxZilla/noob/blob/master/notMNIST.pickle
#code for generating the notMNIST.pickle file-> https://github.com/rndbrtrnd/udacity-deep-learning/blob/master/1_notmnist.ipynb
#***********************DATASET HANDLING************************
#Loading the dataset
with open(pickle_file, 'rb') as f:
save = pickle.load(f)
train_dataset = save['train_dataset']
train_labels = save['train_labels']
valid_dataset = save['valid_dataset']
valid_labels = save['valid_labels']
test_dataset = save['test_dataset']
test_labels = save['test_labels']
del save # hint to help gc free up memory
print('------Before dataset reshaping-----')
print('Training set', train_dataset.shape, train_labels.shape)
print('Validation set', valid_dataset.shape, valid_labels.shape)
print('Test set', test_dataset.shape, test_labels.shape)
#Reshaping the dataset
'''
Reformat into a shape that's more adapted to the models we're going to train:
data as a flat matrix,
labels as float 1-hot encodings.
'''
batch_size = 128
num_hidden_nodes1 = 1024
graph = tf.Graph()
with graph.as_default():
#### Insert code for initializing train, validation, test and regularization data.
# Input data. For the training data, we use a placeholder that will be fed
# at run time with a training minibatch.
# Use validation and test data as constants
'''
tf_train_dataset =
tf_train_labels =
tf_valid_dataset =
tf_test_dataset =
'''
### Insert code for weights and biases (weights1, biases1, weights2, biases2)
'''
weights1 =
biases1 =
weights2 =
biases2 =
'''
# Training computation.
### Insert code for calculating loss using relu, softmax logits
'''
lay1_train =
logits =
loss =
'''
# Optimizer.
### Insert code for optimizing the training using GradientDescentOptimizer
'''
optimizer =
'''
### Insert code for predictions for the training, validation, and test data using softmax and relu
'''
train_prediction =
lay1_valid =
valid_prediction =
lay1_test =
test_prediction =
'''
num_steps = 101
num_batches = 3
with tf.Session(graph=graph) as session:
tf.initialize_all_variables().run()
print("Initialized")
for step in range(num_steps):
### Insert code for randomized offset
'''
offset =
'''
# Generate a minibatch.
### Insert code to generate minibatch from train dataset using offset and batch_size
'''
batch_data =
batch_labels =
'''
### Insert code to prepare a dictionary telling the session where to feed the minibatch.
# The key of the dictionary is the placeholder node of the graph to be fed,
# and the value is the numpy array to feed to it.
'''
feed_dict =
'''
# print accuracy prediction for minibatch and validation sets
if (step % 500 == 0):
print("Minibatch loss at step %d: %f" % (step, l))
print("Minibatch accuracy: %.1f%%" % accuracy(predictions, batch_labels))
print("Validation accuracy: %.1f%%" % accuracy(
valid_prediction.eval(), valid_labels))
# show final accuracy on test set
print("Test accuracy: %.1f%%" % accuracy(test_prediction.eval(), test_labels))