AttributeError: 'module' object has no attribute 'python'というエラーが発生しました。
Using TensorFlow backend. 2021-11-26 16:06:11.023053: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA Traceback (most recent call last): File "9_Layer_CNN.py", line 301, in <module> run_train('9_Layer_CNN') File "9_Layer_CNN.py", line 194, in run_train model = layer_9_model() File "9_Layer_CNN.py", line 146, in layer_9_model model.add(Dropout(0.5)) File "/home/a/anaconda3/envs/main/lib/python2.7/site-packages/keras/models.py", line 308, in add output_tensor = layer(self.outputs[0]) File "/home/a/anaconda3/envs/main/lib/python2.7/site-packages/keras/engine/topology.py", line 515, in __call__ self.add_inbound_node(inbound_layers, node_indices, tensor_indices) File "/home/a/anaconda3/envs/main/lib/python2.7/site-packages/keras/engine/topology.py", line 573, in add_inbound_node Node.create_node(self, inbound_layers, node_indices, tensor_indices) File "/home/a/anaconda3/envs/main/lib/python2.7/site-packages/keras/engine/topology.py", line 150, in create_node output_tensors = to_list(outbound_layer.call(input_tensors[0], mask=input_masks[0])) File "/home/a/anaconda3/envs/main/lib/python2.7/site-packages/keras/layers/core.py", line 91, in call x = K.in_train_phase(K.dropout(x, self.p, noise_shape), x) File "/home/a/anaconda3/envs/main/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 1243, in in_train_phase x = tf.python.control_flow_ops.cond(tf.cast(_LEARNING_PHASE, 'bool'), AttributeError: 'module' object has no attribute 'python'
プログラム名はpython 9_Layer_CNN.pyです。
対応箇所のプログラムは、以下になります。
def in_train_phase(x, alt): '''Selects `x` in train phase, and `alt` otherwise. Note that `alt` should have the *same shape* as `x`. ''' if _LEARNING_PHASE is 1: return x elif _LEARNING_PHASE is 0: return alt # else: assume learning phase is a placeholder. x_shape = copy.copy(x.get_shape()) x = tf.python.control_flow_ops.cond(tf.cast(_LEARNING_PHASE, 'bool'), lambda: x, lambda: alt) x._uses_learning_phase = True x.set_shape(x_shape) return x
このエラーを解決したく思います。
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー