1

假设我有两层卷积模型

Input -> conv -> conv -> flatten -> softmax 10 classes (cross entropy cost function)

我已经使用保存了这个模型

saver = tf.train.Saver(tf.global_variables()) 
....
# run session
saver.save(sess, checkpoint_path, global_step=training_step)

保存后模型数据文件大小约为 13 MB。

接下来,我想用这个模型来进行迁移学习。我删除了之前模型中的最后一个 softmax 层(10 个单元),并在新模型架构中添加了一个新的 conv 和新的 softmax 层(6 个单元)。

sess = tf.InteractiveSession()

# load model trained in previous step
saver = tf.train.import_meta_graph(meta_file)
saver.restore(sess,tf.train.latest_checkpoint(model_dir))

graph = tf.get_default_graph()
output_after_conv = graph.get_tensor_by_name("flatten:0")
# freezed
flatten = tf.stop_gradient(output_after_conv )

saver = tf.train.Saver(tf.global_variables())

input = graph.get_tensor_by_name("input:0")

# constructed input to be feeded
# added a conv layer to the graph
# added softmax layer to the graph
# defined cost function
# defined optimizer

# ran the session then saved the model
saver.save(sess, checkpoint_path, global_step=training_step)  

这次模型数据文件大小增加到 300 MB。我想知道是什么导致了这个模型大小的增长?

4

0 回答 0