在训练用于图像分类任务的卷积神经网络时,我们通常希望我们的算法能够学习将给定图像转换为其正确标签的滤波器(和偏差)。我有几个模型试图在模型大小、操作数量、准确性等方面进行比较。但是,从张量流输出的模型的大小,具体来说是模型.ckpt.数据存储图中所有变量值的文件不是我所期望的。事实上,它似乎大了三倍。
为了直接解决问题,我将根据我的问题thisJupyter 笔记本。下面是定义变量(权重和偏差)的部分:
# Store layers weight & bias
weights = {
# 5x5 conv, 1 input, 32 outputs
'wc1': tf.Variable(tf.random_normal([5, 5, 1, 32]),dtype=tf.float32),
# 5x5 conv, 32 inputs, 64 outputs
'wc2': tf.Variable(tf.random_normal([5, 5, 32, 64]),dtype=tf.float32),
# fully connected, 7*7*64 inputs, 1024 outputs
'wd1': tf.Variable(tf.random_normal([7*7*64, 1024]),dtype=tf.float32),
# 1024 inputs, 10 outputs (class prediction)
'out': tf.Variable(tf.random_normal([1024, num_classes]),dtype=tf.float32)
}
biases = {
'bc1': tf.Variable(tf.random_normal([32]),dtype=tf.float32),
'bc2': tf.Variable(tf.random_normal([64]),dtype=tf.float32),
'bd1': tf.Variable(tf.random_normal([1024]),dtype=tf.float32),
'out': tf.Variable(tf.random_normal([num_classes]),dtype=tf.float32)
}
我添加了几行以便在训练过程结束时保存模型:
# Save the model
save_path = saver.save(sess, logdir+"model.ckpt")
print("Model saved in file: %s" % save_path)
将所有这些变量相加,我们期望得到模型.ckpt.数据文件大小为 12.45Mb(我通过计算模型学习的浮点元素数量,然后将该值转换为兆字节来获得此文件)。但!这.data保存的文件大小为 39.3Mb。为什么是这样?
我对更复杂的网络(ResNet 的变体)采用了相同的方法,并且我预期的模型。数据大小也比实际大小小约 3 倍.data文件是.
所有这些变量的数据类型都是float32。