ValueError:变量A3C_net / basic_lstm_cell / weights不存在,或者未使用tf.get_variable()创建

时间:2017-05-18 11:04:12

标签: python reinforcement-learning

当我用tf.nn.dynamic_rnn构建LSTM时,关于name_scope的问题导致它失败,平台是WINDOWS 10.我无法解决它,任何帮助都将不胜感激。

非常感谢!

整个错误如下:

追踪(最近一次呼叫最后一次):

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#e1e1e1"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/msgListView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/form"
        android:divider="@null"
        android:dividerHeight="0dp"
        android:paddingBottom="10dp"
        android:text="Hello World" />

    <LinearLayout
        android:id="@+id/form"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:background="#91f1f1f1"
        android:orientation="horizontal"
        android:paddingBottom="2dp" >


        <EditText
            android:id="@+id/messageEditText"
            android:layout_width="252dp"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignTop="@+id/button1"
            android:layout_toLeftOf="@+id/sendMessageButton"
            android:layout_weight="0.72"
            android:ems="10"
            android:maxHeight="80dp" />

        <ImageButton
            android:id="@+id/sendMessageButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:background="@drawable/send_button"
            android:text="d" />
    </LinearLayout>

</RelativeLayout>

ValueError:变量A3C_net / basic_lstm_cell / weights不存在,或者未使用tf.get_variable()创建。你的意思是在VarScope中设置reuse = None吗?

  File "a3c_prediction.py", line 157, in <module>
    main()
  File "a3c_prediction.py", line 88, in main
    global_network = ACLSTMNetwork(ACTION_SIZE, device)
  File "C:\Users\xjZhan\Desktop\a3c_predication\a3c_net_lstm.py", line 139, in __init__
    scope = scope)
  File "C:\Program Install\Anaconda3-4.1.0\lib\site-packages\tensorflow\python\ops\rnn.py", line 553, in dynamic_rnn
    dtype=dtype)
  File "C:\Program Install\Anaconda3-4.1.0\lib\site-packages\tensorflow\python\ops\rnn.py", line 720, in _dynamic_rnn_loop
    swap_memory=swap_memory)
  File "C:\Program Install\Anaconda3-4.1.0\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 2623, in while_loop
    result = context.BuildLoop(cond, body, loop_vars, shape_invariants)
  File "C:\Program Install\Anaconda3-4.1.0\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 2456, in BuildLoop
    pred, body, original_loop_vars, loop_vars, shape_invariants)
  File "C:\Program Install\Anaconda3-4.1.0\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 2406, in _BuildLoop
    body_result = body(*packed_vars_for_body)
  File "C:\Program Install\Anaconda3-4.1.0\lib\site-packages\tensorflow\python\ops\rnn.py", line 703, in _time_step
    skip_conditionals=True)
  File "C:\Program Install\Anaconda3-4.1.0\lib\site-packages\tensorflow\python\ops\rnn.py", line 177, in _rnn_step
    new_output, new_state = call_cell()
  File "C:\Program Install\Anaconda3-4.1.0\lib\site-packages\tensorflow\python\ops\rnn.py", line 691, in <lambda>
    call_cell = lambda: cell(input_t, state)
  File "C:\Program Install\Anaconda3-4.1.0\lib\site-packages\tensorflow\contrib\rnn\python\ops\core_rnn_cell_impl.py", line 241, in __call__
    concat = _linear([inputs, h], 4 * self._num_units, True)
  File "C:\Program Install\Anaconda3-4.1.0\lib\site-packages\tensorflow\contrib\rnn\python\ops\core_rnn_cell_impl.py", line 1044, in _linear
    _WEIGHTS_VARIABLE_NAME, [total_arg_size, output_size], dtype=dtype)
  File "C:\Program Install\Anaconda3-4.1.0\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 1049, in get_variable
    use_resource=use_resource, custom_getter=custom_getter)
  File "C:\Program Install\Anaconda3-4.1.0\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 948, in get_variable
    use_resource=use_resource, custom_getter=custom_getter)
  File "C:\Program Install\Anaconda3-4.1.0\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 356, in get_variable
    validate_shape=validate_shape, use_resource=use_resource)
  File "C:\Program Install\Anaconda3-4.1.0\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 341, in _true_getter
    use_resource=use_resource)
  File "C:\Program Install\Anaconda3-4.1.0\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 671, in _get_single_variable
    "VarScope?" % name)

1 个答案:

答案 0 :(得分:0)

解决它非常样本,如下所示:用tf.Variabl替换tf.get_variabl