WARNING:tensorflow:From <ipython-input-4-5a1cbf83da43>:1: read_data_sets (from tensorflow.examples.tutorials.mnist.input_data) is deprecated and will be removed in a future version.
Instructions for updating:
Please use alternatives such as: tensorflow_datasets.load('mnist')
WARNING:tensorflow:From d:\progra~2\python\virtua~1\py37_x64\lib\site-packages\tensorflow_core\examples\tutorials\mnist\input_data.py:297: _maybe_download (from tensorflow.examples.tutorials.mnist.input_data) is deprecated and will be removed in a future version.
Instructions for updating:
Please write your own downloading logic.
WARNING:tensorflow:From d:\progra~2\python\virtua~1\py37_x64\lib\site-packages\tensorflow_core\examples\tutorials\mnist\input_data.py:299: _extract_images (from tensorflow.examples.tutorials.mnist.input_data) is deprecated and will be removed in a future version.
Instructions for updating:
Please use tf.data to implement this functionality.
Extracting data/train-images-idx3-ubyte.gz
WARNING:tensorflow:From d:\progra~2\python\virtua~1\py37_x64\lib\site-packages\tensorflow_core\examples\tutorials\mnist\input_data.py:304: _extract_labels (from tensorflow.examples.tutorials.mnist.input_data) is deprecated and will be removed in a future version.
Instructions for updating:
Please use tf.data to implement this functionality.
Extracting data/train-labels-idx1-ubyte.gz
WARNING:tensorflow:From d:\progra~2\python\virtua~1\py37_x64\lib\site-packages\tensorflow_core\examples\tutorials\mnist\input_data.py:112: _dense_to_one_hot (from tensorflow.examples.tutorials.mnist.input_data) is deprecated and will be removed in a future version.
Instructions for updating:
Please use tf.one_hot on tensors.
Extracting data/t10k-images-idx3-ubyte.gz
Extracting data/t10k-labels-idx1-ubyte.gz
WARNING:tensorflow:From d:\progra~2\python\virtua~1\py37_x64\lib\site-packages\tensorflow_core\examples\tutorials\mnist\input_data.py:328: _DataSet.__init__ (from tensorflow.examples.tutorials.mnist.input_data) is deprecated and will be removed in a future version.
Instructions for updating:
Please use alternatives such as official/mnist/_DataSet.py from tensorflow/models.
MNIST ready
WARNING:tensorflow:From d:\progra~2\python\virtua~1\py37_x64\lib\site-packages\tensorflow_core\python\ops\resource_variable_ops.py:1635: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.
Instructions for updating:
If using Keras pass *_constraint arguments to layers.
training_epochs =15
batch_size =100
display_step =5if do_train ==1:for epoch inrange(training_epochs):
avg_cost =0.#total_batch = int(mnist.train.num_examples/batch_size)
total_batch =10# 比较耗时,所以此处指定为10# Loop over all batchesfor i inrange(total_batch):
batch_xs, batch_ys = mnist.train.next_batch(batch_size)# Fit training using batch data
sess.run(optm, feed_dict={x: batch_xs, y: batch_ys, keepratio:0.7})# Compute average loss
avg_cost += sess.run(cost, feed_dict={x: batch_xs, y: batch_ys, keepratio:1.})/total_batch
# Display logs per epoch stepif epoch % display_step ==0:print("Epoch: %03d/%03d cost: %.9f"%(epoch, training_epochs, avg_cost))
train_acc = sess.run(accr, feed_dict={x: batch_xs, y: batch_ys, keepratio:1.})print(" Training accuracy: %.3f"%(train_acc))
test_acc = sess.run(accr, feed_dict={x: testimg, y: testlabel, keepratio:1.})print(" Test accuracy: %.3f"%(test_acc))# Save Netif epoch % save_step ==0:
saver.save(sess,"save/nets/cnn_mnist_basic.ckpt-"+str(epoch))print("OPTIMIZATION FINISHED")
Epoch: 000/015 cost: nan
Training accuracy: 0.080
Test accuracy: 0.098
WARNING:tensorflow:From d:\progra~2\python\virtua~1\py37_x64\lib\site-packages\tensorflow_core\python\training\saver.py:963: remove_checkpoint (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version.
Instructions for updating:
Use standard file APIs to delete files with this prefix.
Epoch: 005/015 cost: nan
Training accuracy: 0.130
Test accuracy: 0.098
Epoch: 010/015 cost: nan
Training accuracy: 0.100
Test accuracy: 0.098
OPTIMIZATION FINISHED
if do_train ==0:# 读取最后一个模型
epoch = training_epochs-1
saver.restore(sess,"save/nets/cnn_mnist_basic.ckpt-"+str(epoch))
test_acc = sess.run(accr, feed_dict={x: testimg, y: testlabel, keepratio:1.})print(" TEST ACCURACY: %.3f"%(test_acc))
INFO:tensorflow:Restoring parameters from save/nets/cnn_mnist_basic.ckpt-14
TEST ACCURACY: 0.098