前提・実現したいこと
KerasでInstanceNorm層とConvolution層を用いたEncoderを実装したいと思っています
発生している問題・エラーメッセージ
エラーメッセージ --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-3-6a921f9b3839> in <module> 27 )(x) 28 ---> 29 model = build_encoder() <ipython-input-3-6a921f9b3839> in build_encoder(input_shape) 18 activation='relu' 19 )(Input_layer) ---> 20 x = InstanceNormalization()(x) 21 x = Conv2D( 22 128, ~/.pyenv/versions/anaconda3-4.4.0/envs/ml/lib/python3.6/site-packages/keras/engine/base_layer.py in __call__(self, inputs, **kwargs) 441 442 # Handle mask propagation. --> 443 previous_mask = _collect_previous_mask(inputs) 444 user_kwargs = copy.copy(kwargs) 445 if not is_all_none(previous_mask): ~/.pyenv/versions/anaconda3-4.4.0/envs/ml/lib/python3.6/site-packages/keras/engine/base_layer.py in _collect_previous_mask(input_tensors) 1309 inbound_layer, node_index, tensor_index = x._keras_history 1310 node = inbound_layer._inbound_nodes[node_index] -> 1311 mask = node.output_masks[tensor_index] 1312 masks.append(mask) 1313 else: AttributeError: 'Node' object has no attribute 'output_masks'
該当のソースコード
Python
1import numpy as np 2from tensorflow.python import keras 3from tensorflow.python.keras import backend as K 4from tensorflow.python.keras.models import Sequential, Model 5from tensorflow.python.keras.layers import Conv2D, Activation, Input 6from keras_contrib.layers.normalization.instancenormalization import InstanceNormalization 7 8def build_encoder(input_shape=(256,256,3)): 9 Input_layer = Input( 10 shape=input_shape, 11 name='input' 12 ) 13 x = Conv2D( 14 64, 15 3, 16 1, 17 padding='same', 18 activation='relu' 19 )(Input_layer) 20 x = InstanceNormalization()(x) 21 x = Conv2D( 22 128, 23 3, 24 2, 25 padding='same', 26 activation='relu' 27 )(x) 28 29model = build_encoder()
試したこと
試しにソースコード20行目のInstanceNormalization()(x)をInstanceNormalization(x)にしてみると、以下のエラーコードが出ました
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-2-1930bd708f2a> in <module> 27 )(x) 28 ---> 29 model = build_encoder() <ipython-input-2-1930bd708f2a> in build_encoder(input_shape) 25 padding='same', 26 activation='relu' ---> 27 )(x) 28 29 model = build_encoder() ~/.pyenv/versions/anaconda3-4.4.0/envs/ml/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py in __call__(self, inputs, *args, **kwargs) 728 729 # Check input assumptions set before layer building, e.g. input rank. --> 730 self._assert_input_compatibility(inputs) 731 if input_list and self._dtype is None: 732 try: ~/.pyenv/versions/anaconda3-4.4.0/envs/ml/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py in _assert_input_compatibility(self, inputs) 1461 spec.min_ndim is not None or 1462 spec.max_ndim is not None): -> 1463 if x.shape.ndims is None: 1464 raise ValueError('Input ' + str(input_index) + ' of layer ' + 1465 self.name + ' is incompatible with the layer: ' AttributeError: 'InstanceNormalization' object has no attribute 'shape'
またソースコード21-27行目のConv2Dを削除して実行、すなわちInstanceNormalization層以下に何も層を設置しない状態で実行すると、エラーコードは出ませんでした。
補足情報(FW/ツールのバージョンなど)
動作環境は、Jupiter Notebookです
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/12 07:16
2019/06/12 23:15