import tensorflow as tf from tensorflow.keras import layers import matplotlib.pyplot as plt import datetime (x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data() x_test = tf.cast(x_test, dtype=tf.float32) / 255.0 x_train = tf.cast(x_train, dtype=tf.float32) / 255.0 model = tf.keras.Sequential( [layers.Flatten(input_shape=(28, 28)), layers.Dense(128, activation='relu'), layers.Dropout(0.2), layers.Dense(10, activation='softmax')]) # 可视化页面监听数据创建 current_time = datetime.datetime.now().strftime("%Y%m%d-%H%M%S") log_dir = 'logs/' + current_time summary_writer = tf.summary.create_file_writer(log_dir) model.compile(optimizer='rmsprop', loss='sparse_categorical_crossentropy', metrics=['accuracy']) tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir='logs/', histogram_freq=1) model.fit(x_train, y_train, batch_size=150, epochs=40, validation_data=(x_test, y_test), validation_freq=2, callbacks=[tensorboard_callback]) # def get_images(x_test): # images_print = [] # for i in range(len(x_test)): # image = next(iter(x_test)) # model.predict(image) # plt.matshow(image) # images_print += plt.show() # images_print = tf.reshape(images_print, [-1, 50, 50, 1]) # return images_print # # # with summary_writer.as_default(): # tf.summary.image('image', get_images(x_test), step=0)
机器深度学习tensorflow工具编写手写数字识别程序第二版本带可视化图标
时间:2019年09月17日 07:08:35 | 作者 :老马 | 分类 : 业余爱好 | 浏览:956 | 评论:0
本站致力于揭露全国影视投资诈骗案件 避免更多老百姓受骗上当
经历分享 请投稿 |
相关文章
- 2019-09-28图片数据标准化预处理 常用到的两个参数值 mean std 平均值 与 方差 常量
- 2019-09-28tensorflow 谷歌机器学习 之 自定义数据集 之 图片数据 转化为 可处理的tensor类型数据集
- 2019-09-17在训练模型model.compile()中计算loss的常用函数都有哪些?
- 2019-09-17tensorflow学了一个阶段了,做一个小总结
- 2019-09-16 tensorflow算法:手写数字识别练习题
- 2019-09-15tensorflow 线性回归推导
- 2019-09-14关于 pad_Sequence embedding用法 (未完待更新)
- 2019-09-13影视正负面评论数据预处理为向量的方法:one_hot pad_squences举例
- 2019-09-13tensorflow库自动求导函数GradientTape使用
- 2019-09-12tensorflow循环神经网络 之 自定义模型和层完毕后建立训练逻辑的几个重要函数compile、fit、evaluate的使用方法
网络世界,不加微信QQ手机,留言沟通
发表评论