mnist

Ubuntu18.04+python3.6+pip3入门tensorflow

淺唱寂寞╮ 提交于 2019-12-24 17:56:58
Ubuntu18.04+python3.6+pip3入门tensorflow 最近课程要求学习tensorflow,在中文社区跑了一下入门例程,在这总结一下踩的一些坑 学习过程如下: 根据官方入门手册我进行的是最简单的二进制安装cpu版本 pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl 然后就是测试例程: 运行 TensorFlow 打开一个 python 终端: $ python >>> import tensorflow as tf >>> hello = tf.constant('Hello, TensorFlow!') >>> sess = tf.Session() >>> print sess.run(hello) Hello, TensorFlow! >>> a = tf.constant(10) >>> b = tf.constant(32) >>> print sess.run(a+b) 42 >>> 这些都十分顺利,一点问题都没有。 接下来就是: 面向机器学习初学者的 MNIST 初级教程 这是整个新手入门最坑的地方。。。 先来看入门手册开篇: TensorFlow Python API 依赖

tensorflow中手写识别笔记

微笑、不失礼 提交于 2019-12-24 13:56:58
教程链接: https://www.w3cschool.cn/tensorflow_python/tensorflow_python-c1ov28so.html tensorflow 常用的函数: # 导入tensorflow,使用tf代替 import tensorflow as tf # 计算x,和w的乘积,这里计算x矩阵和w矩阵的乘积 tf.matmul(x, w) # 先计算labels和logits的交叉熵(区别),在对结果进行归一化处理, softmax参考 tf.nn.softmax_cross_entropy_with_logits(labels=y_, logits=y) # 然后求交叉熵的平均值 cross_entrony = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y_, logits=y)) # 以梯度下降法,0.5的幅度,减小交叉熵 tf.train.GradientDescentOptimizer(0.5).minimize(cross_entrony) # 初始化变量(tf,Variable()) tf.global_variables_initializer().run() # 获取一行最大值的索引 tf.argmax(y, 1) # 比较a和b对应位置是否是相同的

Cannot run keras

…衆ロ難τιáo~ 提交于 2019-12-24 11:15:07
问题 I want to run keras on anaconda for convolution neural network using mnist handwriting recognition. A day before everything worked fine but as I try to run the same program, i get the following error in the first line: from keras.datasets import mnist (first line of code) ModuleNotFoundError: No module named 'keras.datasets'; 'keras' is not a package I also created virtual environment to use python 3.5 as my python version is 3.6. I have installed both keras and tensorflow. How do i fix the

Trouble reading mnist with tensorflow

ぃ、小莉子 提交于 2019-12-24 10:47:41
问题 So apparently the Yann LeCun's website is down so the following lines for reading mnist with tensorflow don't seem to be working : FROM tensorflow.examples.tutorials.mnist IMPORT input_data mnist = input_data.read_data_sets("MNIST_data/", one_hot = true) Any ideas how can i read the mnist without using these above lines? 回答1: You can access the website here: https://web.archive.org/web/20160117040036/http://yann.lecun.com/exdb/mnist/ - download the data, and read it in from a local copy...

Training with an input size of 1 causes NaN in subsequent predictions

倖福魔咒の 提交于 2019-12-24 08:04:07
问题 I'm following the MNIST tutorial here for recognizing handwritten characters. I'm able to load and recognize handwritten digits without issue, but now I want to train the model again on new images (specifically one at a time). For some reason, when I choose a training size equal to 1, all my predictions become NaN. If I pick a value >=2, it works fine. Train Function: async function train(model, data) { const TRAIN_DATA_SIZE = 1; // WHEN THIS IS 1, CAUSES PREDICT TO OUTPUT NaN const [trainXs,

Resize MNIST Data on Tensorflow

感情迁移 提交于 2019-12-24 07:36:57
问题 I have been working on MNIST dataset to learn how to use Tensorflow and Python for my deep learning course. I could read the data internally/externally and also train it in softmax and cnn thanks to tensorflow tutorial at website. At the end, I could get >%90 in softmax, >%98 in cnn, accuracy. My problem is that I want to resize all images on MNIST as 14x14 and train it again, also to augment all (noising, rotating etc.) and train again. At the end, I want to be able to compare the accuracies

How to get the value from each output-node during eval MNIST testdata in TensorFlow?

。_饼干妹妹 提交于 2019-12-24 07:07:12
问题 I train a convolutional neural network (CNN) with TensorFlow. When the training is finished I calculate the accuracy with the following code: ... correct = tf.equal(tf.argmax(prediction, 1), tf.argmax(y, 1)) accuracy = tf.reduce_mean(tf.cast(correct, tf.float32)) eval_batch_size = 1 good = 0 total = 0 for i in range(int(mnist.test.num_examples/eval_batch_size)): testSet = mnist.test.next_batch(eval_batch_size, shuffle=False) good += accuracy.eval(feed_dict={ x: testSet[0], y: testSet[1]})

How to freeze weights in certain layer with Keras?

二次信任 提交于 2019-12-24 05:15:10
问题 I am trying to freeze the weights of certain layer in a prediction model with Keras and mnist dataset, but it does not work. The code is like: from keras.layers import Dense, Flatten from keras.utils import to_categorical from keras.models import Sequential, load_model from keras.datasets import mnist from keras.losses import categorical_crossentropy import numpy as np def load_data(): (x_train, y_train), (x_test, y_test) = mnist.load_data() x_train = x_train.astype('float32') x_test = x_test

tensorflow(五)

て烟熏妆下的殇ゞ 提交于 2019-12-24 03:08:23
一、单机编程框架 单机程序是指启动和运行都在一台机器的一个进程中完成,因为没有网络开销,非常适合参数不多、计算量小的模型。 步骤,创建单机数据流图,创建并运行单机会话。 saver = tf.train.Saver() sess = tf.InteractiveSession() tf.global_variables_initializer().run() for i in range(1000): batch_xs,batch_ys = mnist.train.next_batch(100) sess.run(train_step,feed_dict={x:batch_xs,y_=batch_ys}) if i%100 = 0: saver.save(sess,'mnist.ckpt') correct_prediction = tf.equal(tf.argmax(y,1),tf.argmax(y_,1)) accuracy = tf.reduce_mean(tf.cast(correct_prediction,tf.float32)) sess.run(accuracy,feed_dict={x:mnist.test.images,y_:mnist.test.labels}) 如果想指定机器上的设备如cpu,gpu 可以使用 with tf.device('/cpu:0')

How to sort MNIST digits into each class label?

孤街浪徒 提交于 2019-12-23 23:26:47
问题 I'm importing mnist dataset from Keras using (x_train, y_train), (x_test, y_test) = mnist.load_data() and what I want to do is sort each sample by it's corresponding digit. I'm imagining some trivial way to do this but I can't seem to find any label attribute of the data. Any simple way to do this? 回答1: y_train and y_test are the vectors containing the label associated with each image in x_train and x_test respectively. That will tell you the digit shown in each image. So just get the indices