Comments (2)
oh I got it!
silly me miscalculated img_size_flattened = 728
!
from tensorflow-tutorials.
I am trying to run the MNIST code without any error from the below code ( segment 1) , however at the time of restoring the model which is in segment 2 below , i am getting the error as : Cannot feed value of shape (784,) for Tensor 'input:0', which has shape '(?, 784) , kindly suggest
segment 1
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
import matplotlib.pyplot as plt
from random import randint
import numpy as np
logs_path = 'log_mnist_softmax'
batch_size = 100
learning_rate = 0.5
training_epochs = 10
mnist = input_data.read_data_sets("data", one_hot=True)
X = tf.placeholder(tf.float32, [None, 784], name = "input")
Y_ = tf.placeholder(tf.float32, [None, 10])
W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))
XX = tf.reshape(X, [-1, 784])
Y = tf.matmul(X, W) + b
cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=Y_, logits=Y), name = "output")
correct_prediction = tf.equal(tf.argmax(Y, 1), tf.argmax(Y_, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
train_step = tf.train.GradientDescentOptimizer(0.005).minimize(cross_entropy)
tf.summary.scalar("cost", cross_entropy)
tf.summary.scalar("accuracy", accuracy)
summary_op = tf.summary.merge_all()
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
writer = tf.summary.FileWriter(logs_path,
graph=tf.get_default_graph())
for epoch in range(training_epochs):
batch_count = int(mnist.train.num_examples / batch_size)
for i in range(batch_count):
batch_x, batch_y = mnist.train.next_batch(batch_size)
, summary = sess.run([train_step, summary_op], feed_dict={X: batch_x, Y: batch_y})
writer.add_summary(summary, epoch * batch_count + i)
print("Epoch: ", epoch)
print("Accuracy: ", accuracy.eval(feed_dict={X: mnist.test.images, Y_: mnist.test.labels}))
print("done")
num = randint(0, mnist.test.images.shape[0])
img = mnist.test.images[num]
classification = sess.run(tf.argmax(Y, 1), feed_dict={X: [img]})
print('Neural Network predicted', classification[0])
print('Real label is:', np.argmax(mnist.test.labels[num]))
saver = tf.train.Saver()
save_path = saver.save(sess, "data/saved_mnist_cnn.ckpt")
print("Model saved to %s" % save_path)
Segment 2 for restoring the model
import matplotlib.pyplot as plt
import tensorflow as tf
import numpy as np
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('data', one_hot=True)
sess = tf.InteractiveSession()
new_saver = tf.train.import_meta_graph('data\saved_mnist_cnn.ckpt.meta')
new_saver.restore(sess, 'data\saved_mnist_cnn.ckpt')
tf.get_default_graph().as_graph_def()
x = sess.graph.get_tensor_by_name("input:0")
y_conv = sess.graph.get_tensor_by_name("output:0")
image_b = mnist.test.images[100]
result = sess.run(y_conv, feed_dict={x:image_b})
print(result)
print(sess.run(tf.argmax(result, 1)))
plt.imshow(image_b.reshape([28, 28]), cmap='Greys')
plt.show()
from tensorflow-tutorials.
Related Issues (20)
- when i was trying to run this code in pycharm it unables to download inception package and it results to an error ImportError: No module named 'inception' so please help me to overcome on this issue HOT 1
- Tutorial 23: Memory Error HOT 1
- ValueError: Unknown loss function:sparse_cross_entropy HOT 2
- Tutorial 21 Already Exists Error HOT 1
- 23_Time-Series-Prediction.ipynb - Predicting future values when have no test data? HOT 2
- Deprecated scipy libraries HOT 3
- acc = sess.run(accuracy, feed_dict={x: mnist.test.images, y: mnist.test.Lables}) AttributeError: 'DataSet' object has no attribute 'Lables' HOT 2
- using Elmo embedding layer in image captioning model ( Tutorial #22) HOT 1
- Image Caption works poorly HOT 6
- Tutorial 20 ValueError in Keras HOT 3
- TensorFlow 2.0 HOT 3
- Now how to forecast the future without knowing the known values? HOT 2
- AttributeError: module 'tensorflow' has no attribute 'gfile' in style transfer notebook HOT 3
- model.prediction does not match model.evaluation loss error HOT 3
- Tutorial 23 Error: Supplying multiple axes to axis is no longer supported. HOT 1
- ValueError: could not convert string to float: '28-12-2017'. I am training the time series prediction model on stock market data set and faced this error HOT 1
- issue when implementing image caption model HOT 4
- module 'tensorflow.python.ops.variable_scope' has no attribute '_VARSCOPE_KEY' HOT 2
- Korean translation HOT 2
- Tutorial 22_Image_Captioning.ipynb is not working in Colab because of disk space limit HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tensorflow-tutorials.