質問内容
オートエンコーダを用いた画像の異常検知をしていたところ際に学習まではうまくいったのですが、実際に異常箇所を特定するところで、以下のようなエラーが発生してしまいました。
また、resize_original_images内に存在する画像データはすべて(300, 300, 3)のshapeに統一されています。
実際のコード
files = glob.glob("/content/drive/MyDrive/resize_original_images/*.jpg") evaluation_image=[] for l in files: images = cv2.imread(l) images = cv2.cvtColor(images, cv2.COLOR_BGR2RGB) evaluation_image.append(images) evaluation_image = np.array(evaluation_image) evaluation_image = evaluation_image.astype('float32')/255 for e in evaluation_image: z_points = encoder.predict(e) reconst_images = decoder.predict(z_points) # 元画像との差分を計算 diff_images = np.absolute(reconst_images - e) print(diff_images)
エラーコード
/usr/local/lib/python3.8/dist-packages/tensorflow/python/data/ops/structured_function.py:264: UserWarning: Even though the `tf.config.experimental_run_functions_eagerly` option is set, this option does not apply to tf.data functions. To force eager execution of tf.data functions, please use `tf.data.experimental.enable_debug_mode()`. warnings.warn( --------------------------------------------------------------------------- /usr/local/lib/python3.8/dist-packages/tensorflow/python/data/ops/structured_function.py:264: UserWarning: Even though the `tf.config.experimental_run_functions_eagerly` option is set, this option does not apply to tf.data functions. To force eager execution of tf.data functions, please use `tf.data.experimental.enable_debug_mode()`. warnings.warn( --------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-8-4e904f052eee> in <module> 9 evaluation_image = evaluation_image.astype('float32')/255 10 for e in evaluation_image: ---> 11 z_points = encoder.predict(e) 12 reconst_images = decoder.predict(z_points) 13 # 元画像との差分を計算 1 frames /usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py in error_handler(*args, **kwargs) 65 except Exception as e: # pylint: disable=broad-except 66 filtered_tb = _process_traceback_frames(e.__traceback__) ---> 67 raise e.with_traceback(filtered_tb) from None 68 finally: 69 del filtered_tb /usr/local/lib/python3.8/dist-packages/keras/engine/input_spec.py in assert_input_compatibility(input_spec, inputs, layer_name) 262 if spec_dim is not None and dim is not None: 263 if spec_dim != dim: --> 264 raise ValueError(f'Input {input_index} of layer "{layer_name}" is ' 265 'incompatible with the layer: ' 266 f'expected shape={spec.shape}, ' ValueError: Input 0 of layer "model_6" is incompatible with the layer: expected shape=(None, 300, 300, 3), found shape=(32, 300, 3)

回答1件
あなたの回答
tips
プレビュー