目录
对第九章案例9-8进行了上级实验,根据书本提供的网址下载了代码和数据集。
主要改动如下:
一、关于建立自己的模块并引用
源码中from libs.utils import *,这个因该是作者自己建立的模块,没有下载。于是自己尝试建立自己的模块。分析代码有3个函数:weight_variable(),bias_variable() and montage()。
实验了两种方式:
(一)
1.在源文件同目录下建立文件夹libs,而后在libs文件夹中建立两个文件__init__.py and utils.py;
2. __init__.py文件内容为空。只有文件夹包含此文件,此文件夹才被当作一个包。该文件内容可以为空,也可初始化一些变量等。
3.utils.py中包含3个函数,代码如下:
import tensorflow as tf import numpy as np '''解释说明''' def weight_variable(shape): return tf.Variable(tf.truncated_normal(shape, dtype=tf.float32, stddev=1e-1), name='weights') def bias_variable(shape): return tf.Variable(tf.constant(0.0, shape=shape, dtype=tf.float32)) def montage(s): temp = []