Tensorflow model for training the CNN on the Ck+ dataset
aaronward / model-training-tensorflow Goto Github PK
View Code? Open in Web Editor NEWTensorflow model for training the CNN on the Ck+ dataset
Tensorflow model for training the CNN on the Ck+ dataset
I feed in a random sample of 10 test data images and most of the time (probably 9 times out of 10) i returns the number sequence of the same number, like [ 2 2 2 2 2 2 2 2 2 2] or [1 1 1 1 1 1 1 1 1 1 1 ]
def test_network(x, images, labels):
sample_images, sample_labels = random_sample(images, labels)
sample_images = np.array(sample_images).astype(float)
pred = convolutional_network(x)
correct_pred = tf.argmax(pred, 1)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
saver = tf.train.import_meta_graph(TRAINED_MODEL + 'trained_model.ckpt.meta')
saver.restore(sess, TRAINED_MODEL + 'trained_model.ckpt' )
print('session restored...')
#Here is where i feed the 10 random images
predicted = sess.run([correct_pred], feed_dict={x: sample_images})[0]
print('Correct Labels: ', sample_labels)
print('Predicted Labels: ', predicted)
#Plot the images samples in a grid with the predicted
#outputs and the true outputs
fig = plt.figure(figsize=(10, 10))
for i in range(len(sample_images)):
truth = sample_labels[i]
prediction = predicted[i]
plt.subplot(5, 2,1+i)
plt.axis('off')
color='green' if truth == prediction else 'red'
plt.text(60, 10, "Correct: {0}\nPrediction: {1}".format(truth, prediction),
fontsize=12, color=color)
plt.imshow(sample_images[i], cmap='gray')
plt.show()
test_network(x, images, labels)
it's happening because of correct_pred = tf.argmax(pred, 1), it's giving you
class with the highest probability after the softmax. You can use predicted
= sess.run(pred, feed_dict={x: test_images[0:10]}). Now, you will get
probability of each class for given images For example you might
get [.1, .05, .05 , .6, .1, .1] for your 6 classes. You won't get [0,0,0,1,0,0].
Now, argmax will give you index corresponding to .6.
Also, add :
pred_ = tf.nn.softmax(pred)
predicted = sess.run(pred_, feed_dict={x: test_images[0:10]})
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.