在一个同事写的项目上工作;不明白他做了什么,他有点离开城镇。我的猜测是两个优化器试图使用相同的“OptimizeLoss / beta1_power”副本,但这没有意义,因为代码之前有效,如果这是一个问题,CNN怎么可能工作?
我们正在Jupyter笔记本中开发CNN模型,以便在应用程序中使用。
ValueError Traceback (most recent call last)
<ipython-input-8-0a28e84925b8> in <module>()
6 train_model(X_train, y_train, X_val, y_val, vgg_model, max_steps=10000, optimizer_type="adam", lr=0.001, batch_size=128, checkpoint_dir=checkpoint_dir, augment_data=False,
----> 8 reg_lambda=0.01)
10 # evaluate model
<ipython-input-4-5353196dc790> in train_model(X_train, y_train, X_val, y_val, model, max_steps, optimizer_type, lr, batch_size, augment_data, reg_lambda, steps_per_train_summary, steps_per_checkpoint, steps_per_val, checkpoint_dir)
105
106 # define saver
--> 107 saver = tf.train.Saver()
108
109 step = 0
~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/training/saver.py in __init__(self, var_list, reshape, sharded, max_to_keep, keep_checkpoint_every_n_hours, name, restore_sequentially, saver_def, builder, defer_build, allow_empty, write_version, pad_step_number, save_relative_paths, filename)
1237 self._filename = filename
1238 if not defer_build and context.in_graph_mode():
-> 1239 self.build()
1240 if self.saver_def:
1241 self._check_saver_def()
~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/training/saver.py in build(self)
1246 if context.in_eager_mode():
1247 raise RuntimeError("Use save/restore instead of build in eager mode.")
-> 1248 self._build(self._filename, build_save=True, build_restore=True)
1249
1250 def _build_eager(self, checkpoint_path, build_save, build_restore):
~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/training/saver.py in _build(self, checkpoint_path, build_save, build_restore)
1282 restore_sequentially=self._restore_sequentially,
1283 filename=checkpoint_path,
-> 1284 build_save=build_save, build_restore=build_restore)
1285 elif self.saver_def and self._name:
1286 # Since self._name is used as a name_scope by builder(), we are
~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/training/saver.py in _build_internal(self, names_to_saveables, reshape, sharded, max_to_keep, keep_checkpoint_every_n_hours, name, restore_sequentially, filename, build_save, build_restore)
741 raise ValueError("Graph mode needs to build save and restore together.")
742
--> 743 saveables = self._ValidateAndSliceInputs(names_to_saveables)
744 if max_to_keep is None:
745 max_to_keep = 0
~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/training/saver.py in _ValidateAndSliceInputs(self, names_to_saveables)
594 """
595 if not isinstance(names_to_saveables, dict):
--> 596 names_to_saveables = BaseSaverBuilder.OpListToDict(names_to_saveables)
597
598 saveables = []
~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/training/saver.py in OpListToDict(op_list, convert_variable_to_tensor)
559 if name in names_to_saveables:
560 raise ValueError("At least two variables have the same name: %s" %
--> 561 name)
562 names_to_saveables[name] = var
563 else:
ValueError: At least two variables have the same name: OptimizeLoss/beta1_power
答案 0 :(得分:0)
我通过调用
解决了这个问题tf.reset_default_graph()