Open dengyin opened 2 years ago
It seems to require you to set reuse=tf.AUTO_REUSE
It seems to require you to set reuse=tf.AUTO_REUSE
when i set reuse=tf.AUTO_REUSE and run 'print(model.evaluate(input_fn=lambda: eval_input_fn(test, test_y)))', the dense layers have a new weight actually.The trained weight isn't shared.
New Issue Checklist
Issue Description
希望将tensorlayer用于自定义estimator,Dropout layer在estimator的训练、预测模式切换时报错。
Reproducible Code
版本: tensorflow = 1.13.1 tensorlayer = 1.11.1
报错信息
-----------------------define model____ INFO:tensorflow:Using default config. WARNING:tensorflow:Using temporary folder as model directory: C:\Users\dengyin\AppData\Local\Temp\tmpw0csioqr INFO:tensorflow:Using config: {'_model_dir': 'C:\Users\dengyin\AppData\Local\Temp\tmpw0csioqr', '_tf_random_seed': None, '_save_summary_steps': 100, '_save_checkpoints_steps': None, '_save_checkpoints_secs': 600, '_session_config': allow_soft_placement: true graph_options { rewrite_options { meta_optimizer_iterations: ONE } } , '_keep_checkpoint_max': 5, '_keep_checkpoint_every_n_hours': 10000, '_log_step_count_steps': 100, '_train_distribute': None, '_device_fn': None, '_protocol': None, '_eval_distribute': None, '_experimental_distribute': None, '_service': None, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x0000020297831668>, '_task_type': 'worker', '_task_id': 0, '_global_id_in_cluster': 0, '_master': '', '_evaluation_master': '', '_is_chief': True, '_num_ps_replicas': 0, '_num_worker_replicas': 1} WARNING:tensorflow:Estimator's model_fn (<function model_fn at 0x000002028E861E18>) includes params argument, but params are not passed to Estimator. -----------------------train model____ INFO:tensorflow:Calling model_fn. [TL] InputLayer model/input_SepalLength: (?,) [TL] ReshapeLayer model/reshape_SepalLength: (?, 1) [TL] InputLayer model/input_SepalWidth: (?,) [TL] ReshapeLayer model/reshape_SepalWidth: (?, 1) [TL] InputLayer model/input_PetalLength: (?,) [TL] ReshapeLayer model/reshape_PetalLength: (?, 1) [TL] InputLayer model/input_PetalWidth: (?,) [TL] ReshapeLayer model/reshape_PetalWidth: (?, 1) [TL] ConcatLayer model/concat_layer: axis: 1 [TL] DropoutLayer model/drop1: keep: 0.500000 is_fix: True WARNING:tensorflow:From D:\Program Files\Anaconda3\envs\tf1\lib\site-packages\tensorlayer\layers\dropout.py:100: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version. Instructions for updating: Please use", line 128, in
print(model.evaluate(input_fn=lambda: eval_input_fn(test, test_y)))
File "D:\Program Files\Anaconda3\envs\tf1\lib\site-packages\tensorflow_estimator\python\estimator\estimator.py", line 469, in evaluate
name=name)
File "D:\Program Files\Anaconda3\envs\tf1\lib\site-packages\tensorflow_estimator\python\estimator\estimator.py", line 511, in _actual_eval
return _evaluate()
File "D:\Program Files\Anaconda3\envs\tf1\lib\site-packages\tensorflow_estimator\python\estimator\estimator.py", line 493, in _evaluate
self._evaluate_build_graph(input_fn, hooks, checkpoint_path))
File "D:\Program Files\Anaconda3\envs\tf1\lib\site-packages\tensorflow_estimator\python\estimator\estimator.py", line 1424, in _evaluate_build_graph
self._call_model_fn_eval(input_fn, self.config))
File "D:\Program Files\Anaconda3\envs\tf1\lib\site-packages\tensorflow_estimator\python\estimator\estimator.py", line 1460, in _call_model_fn_eval
features, labels, model_fn_lib.ModeKeys.EVAL, config)
File "D:\Program Files\Anaconda3\envs\tf1\lib\site-packages\tensorflow_estimator\python\estimator\estimator.py", line 1112, in _call_model_fn
model_fn_results = self._model_fn(features=features, *kwargs)
File "", line 55, in model_fn
logits = inference(x, reuse, is_training)
File "", line 21, in inference
network = tl.layers.DenseLayer(network, n_units=800, act=tf.nn.relu, name='relu1')
File "D:\Program Files\Anaconda3\envs\tf1\lib\site-packages\tensorlayer\decorators\deprecated_alias.py", line 24, in wrapper
return f( args, kwargs)
File "D:\Program Files\Anaconda3\envs\tf1\lib\site-packages\tensorlayer\layers\dense\base_dense.py", line 90, in init
name='W', shape=(n_in, n_units), initializer=W_init, dtype=LayersConfig.tf_dtype, self.W_init_args
File "D:\Program Files\Anaconda3\envs\tf1\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 1479, in get_variable
aggregation=aggregation)
File "D:\Program Files\Anaconda3\envs\tf1\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 1220, in get_variable
aggregation=aggregation)
File "D:\Program Files\Anaconda3\envs\tf1\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 547, in get_variable
aggregation=aggregation)
File "D:\Program Files\Anaconda3\envs\tf1\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 499, in _true_getter
aggregation=aggregation)
File "D:\Program Files\Anaconda3\envs\tf1\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 866, in _get_single_variable
"reuse=tf.AUTO_REUSE in VarScope?" % name)
ValueError: Variable model/relu1/W does not exist, or was not created with tf.get_variable(). Did you mean to set reuse=tf.AUTO_REUSE in VarScope?
rate
instead ofkeep_prob
. Rate should be set torate = 1 - keep_prob
. [TL] DenseLayer model/relu1: 800 relu [TL] DropoutLayer model/drop2: keep: 0.500000 is_fix: True [TL] DenseLayer model/relu2: 800 relu [TL] DropoutLayer model/drop3: keep: 0.500000 is_fix: True [TL] DenseLayer model/output: 3 No Activation WARNING:tensorflow:From D:\Program Files\Anaconda3\envs\tf1\lib\site-packages\tensorflow\python\ops\losses\losses_impl.py:209: to_float (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.cast instead. INFO:tensorflow:Done calling model_fn. INFO:tensorflow:Create CheckpointSaverHook. INFO:tensorflow:Graph was finalized. 2021-07-15 11:42:38.703488: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2 INFO:tensorflow:Running local_init_op. INFO:tensorflow:Done running local_init_op. INFO:tensorflow:Saving checkpoints for 0 into C:\Users\dengyin\AppData\Local\Temp\tmpw0csioqr\model.ckpt. INFO:tensorflow:loss = 5.330352, step = 1 INFO:tensorflow:global_step/sec: 54.1661 INFO:tensorflow:loss = 0.72782683, step = 101 (1.846 sec) INFO:tensorflow:global_step/sec: 55.258 INFO:tensorflow:loss = 0.6588603, step = 201 (1.810 sec) INFO:tensorflow:global_step/sec: 55.136 INFO:tensorflow:loss = 0.56736594, step = 301 (1.814 sec) INFO:tensorflow:global_step/sec: 55.9102 INFO:tensorflow:loss = 0.5070057, step = 401 (1.789 sec) INFO:tensorflow:Saving checkpoints for 500 into C:\Users\dengyin\AppData\Local\Temp\tmpw0csioqr\model.ckpt. INFO:tensorflow:Loss for final step: 0.5071666. -----------------------eval model____ INFO:tensorflow:Calling model_fn. [TL] InputLayer model/input_SepalLength: (?,) [TL] ReshapeLayer model/reshape_SepalLength: (?, 1) [TL] InputLayer model/input_SepalWidth: (?,) [TL] ReshapeLayer model/reshape_SepalWidth: (?, 1) [TL] InputLayer model/input_PetalLength: (?,) [TL] ReshapeLayer model/reshape_PetalLength: (?, 1) [TL] InputLayer model/input_PetalWidth: (?,) [TL] ReshapeLayer model/reshape_PetalWidth: (?, 1) [TL] ConcatLayer model/concat_layer: axis: 1 [TL] DropoutLayer model/drop1: keep: 0.500000 is_fix: True [TL] skip DropoutLayer [TL] DenseLayer model/relu1: 800 relu Traceback (most recent call last): File "D:\Program Files\Anaconda3\envs\tf1\lib\site-packages\IPython\core\interactiveshell.py", line 3343, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "