前提
Kerasの公式ブログを参考に、画像のノイズ除去のCNNを構築しようとしています。https://keras.io/examples/vision/autoencoder/
ブログではmnistから画像を読み込んでいるところを、ディレクトリから読み込むように変更したところ、以下のエラーが発生しました。
実現したいこと
ImageDataGenerator, flow_from_directoryを用いて画像をディレクトリから読み込みたい。
発生している問題・エラーメッセージ
Found 0 images belonging to 0 classes. Found 0 images belonging to 0 classes. Found 0 images belonging to 0 classes. Found 0 images belonging to 0 classes. 2022-10-06 11:36:48.762114: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found 2022-10-06 11:36:48.769260: W tensorflow/stream_executor/cuda/cuda_driver.cc:263] failed call to cuInit: UNKNOWN ERROR (303) 2022-10-06 11:36:48.774327: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: DESKTOP 2022-10-06 11:36:48.776891: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: DESKTOP- 2022-10-06 11:36:48.781744: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX2 To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. Model: "model" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= input_1 (InputLayer) [(None, 1024, 1024, 1)] 0 _________________________________________________________________ conv2d (Conv2D) (None, 1024, 1024, 32) 320 _________________________________________________________________ max_pooling2d (MaxPooling2D) (None, 512, 512, 32) 0 _________________________________________________________________ conv2d_1 (Conv2D) (None, 512, 512, 32) 9248 _________________________________________________________________ max_pooling2d_1 (MaxPooling2 (None, 256, 256, 32) 0 _________________________________________________________________ conv2d_transpose (Conv2DTran (None, 512, 512, 32) 9248 _________________________________________________________________ conv2d_transpose_1 (Conv2DTr (None, 1024, 1024, 32) 9248 _________________________________________________________________ conv2d_2 (Conv2D) (None, 1024, 1024, 1) 289 ================================================================= Total params: 28,353 Trainable params: 28,353 Non-trainable params: 0 _________________________________________________________________ Traceback (most recent call last): File "c:\Users\a_\Desktop\Python\Keras\CNN_denoising.py", line 194, in <module> autoencoder.fit( File "C:\Users\a_\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow\python\keras\engine\training.py", line 1137, in fit data_handler = data_adapter.get_data_handler( File "C:\Users\a_\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow\python\keras\engine\data_adapter.py", line 1394, in get_data_handler return DataHandler(*args, **kwargs) File "C:\Users\a_\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow\python\keras\engine\data_adapter.py", line 1149, in __init__ self._adapter = adapter_cls( File "C:\Users\a_\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow\python\keras\engine\data_adapter.py", line 797, in __init__ raise ValueError("`y` argument is not supported when using " ValueError: `y` argument is not supported when using python generator as input.
該当のソースコード
Python
1train_data_dir = "D:/python/Object"#ノイズなし訓練画像 2img_height = 1024 3img_width = 1024 4batch_size = 32 5 6train_datagen = ImageDataGenerator(rescale=1.0 / 255) 7train_data = train_datagen.flow_from_directory( 8 directory = train_data_dir, target_size = (img_height, img_width), color_mode='grayscale', 9 class_mode='input', batch_size=batch_size, shuffle=True 10) 11 12noisy_train_data_dir = "D:/python/Result"#ノイズあり訓練画像 13noisy_train_datagen = ImageDataGenerator(rescale=1.0 / 255) 14noisy_train_data = noisy_train_datagen.flow_from_directory( 15 directory = noisy_train_data_dir, target_size = (img_height, img_width), color_mode='grayscale', 16 class_mode='input', batch_size=batch_size, shuffle=True 17) 18 19test_data_dir = "D:/python/Object"#ノイズなしテスト画像 20test_datagen = ImageDataGenerator(rescale=1.0 / 255) 21test_data = test_datagen.flow_from_directory( 22 directory = test_data_dir, target_size = (img_height, img_width), color_mode='grayscale', 23 class_mode='input', batch_size=batch_size, shuffle=True 24) 25 26noisy_test_data_dir = "D:/python/Result"#ノイズありテスト画像 27noisy_test_datagen = ImageDataGenerator(rescale=1.0 / 255) 28noisy_test_data = noisy_test_datagen.flow_from_directory( 29 directory = noisy_test_data_dir, target_size = (img_height, img_width), color_mode='grayscale', 30 class_mode='input', batch_size=batch_size, shuffle=True 31) 32 33 34autoencoder.fit( 35 train_data, 36 train_data, 37 epochs=50, 38 batch_size=128, 39 shuffle=True, 40 validation_data=(test_data, test_data), 41)
試したこと
ImageDataGeneratorを用いず、リストに画像を読み込ませる方法では正常に動いているようです。
引数class_mode を Noneやbinaryなどに変更してみたが同様のエラーがでました。
補足情報(FW/ツールのバージョンなど)
windows10 pro
Python 3.10.4
tensorflow 2.10.0
回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
また依頼した内容が修正された場合は、修正依頼を取り消すようにしましょう。
2022/10/06 08:03
2022/10/06 08:11
2022/10/06 08:32
2022/10/06 08:39 編集