estoy programando una red neuronal convolucional simple para clasificar imágenes pero al ejecutar el código me salta este error que dice:
ValueError: Asked to retrieve element 0, but the Sequence has length 0
no he logrado encontrar donde puede estar el error, este es mi código:
import sys
import os
import tensorflow as tf
from tensorflow.python.keras.preprocessing.image import ImageDataGenerator
from tensorflow.python.keras import optimizers
from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.layers import Dropout, Flatten, Dense, Activation
from tensorflow.python.keras.layers import Convolution2D, MaxPooling2D
from tensorflow.python.keras import backend as K
K.clear_session()
data_entrenamiento = './data/entrenamiento'
data_validacion = './data/validacion'
epochs = 20
steps_per_epoch = 1000
altura, longitud = 100, 100
batch_size = 32
steps_validation = 200
filtroConv1 = 32
filtroConv2 = 64
filtroConv1_size = (3,3)
filtroConv2_size = (2,2)
pool_size = (2,2)
tipos_imagen = 3
lr = 0.0005
entrenamiento_datagen = ImageDataGenerator(
rescale = 1./255,
shear_range = 0.3,
zoom_range = 0.3,
horizontal_flip = True
)
validacion_datagen = ImageDataGenerator(
rescale = 1./2
)
imagen_entrenamiento = entrenamiento_datagen.flow_from_directory(
data_entrenamiento,
target_size = (altura, longitud),
batch_size = batch_size,
class_mode = 'categorical'
)
imagen_validacion = validacion_datagen.flow_from_directory(
data_validacion,
target_size = (altura, longitud),
batch_size = batch_size,
class_mode = 'categorical'
)
cnn = Sequential()
cnn.add(Convolution2D(filtroConv1, filtroConv1_size, padding = 'same', input_shape = (altura, longitud, 3), activation = 'relu'))
cnn.add(MaxPooling2D(pool_size = pool_size))
cnn.add(Convolution2D(filtroConv2, filtroConv2_size, padding = 'same'))
cnn.add(MaxPooling2D(pool_size = pool_size))
cnn.add(Flatten())
cnn.add(Dense(256, activation = 'relu'))
cnn.add(Dropout(0.5))
cnn.add(Dense(tipos_imagen, activation = 'softmax'))
cnn.compile(loss = 'categorical_crossentropy', optimizer = tf.keras.optimizers.Adam(lr = lr), metrics = ['accuracy'])
cnn.fit(imagen_entrenamiento, steps_per_epoch = steps_per_epoch, epochs = epochs, validation_data = imagen_validacion, validation_steps = steps_validation)
dir = './model/'
if not os.path.exists(dir):
os.mkdir(dir)
cnn.save('./model/modelo.h5')
cnn.save_weights('./model/pesos.h5')
y al ejecutarlo en la terminal me sale lo siguiente:
2020-12-07 11:42:03.396506: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not
load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-12-07 11:42:03.396601: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Found 0 images belonging to 0 classes.
Found 0 images belonging to 0 classes.
2020-12-07 11:42:04.917728: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library nvcuda.dll
2020-12-07 11:42:04.940285: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1716] Found device 0 with properties:
pciBusID: 0000:2d:00.0 name: GeForce RTX 2080 SUPER computeCapability: 7.5
coreClock: 1.83GHz coreCount: 48 deviceMemorySize: 8.00GiB deviceMemoryBandwidth: 462.00GiB/s
2020-12-07 11:42:04.941223: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-12-07 11:42:04.941984: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cublas64_10.dll'; dlerror: cublas64_10.dll not found
2020-12-07 11:42:04.944074: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cufft64_10.dll
2020-12-07 11:42:04.944922: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library curand64_10.dll
2020-12-07 11:42:04.948491: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cusolver64_10.dll
2020-12-07 11:42:04.949270: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cusparse64_10.dll'; dlerror: cusparse64_10.dll not found
2020-12-07 11:42:04.950072: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudnn64_7.dll'; dlerror: cudnn64_7.dll not found
2020-12-07 11:42:04.950114: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1753] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
2020-12-07 11:42:04.950536: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations: AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2020-12-07 11:42:04.958312: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x26377a1d2a0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-12-07 11:42:04.958403: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
2020-12-07 11:42:04.958820: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1257] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-12-07 11:42:04.959089: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1263]
Traceback (most recent call last):
File "trainer.py", line 76, in <module>
cnn.fit(imagen_entrenamiento, steps_per_epoch = steps_per_epoch, epochs = epochs, validation_data = imagen_validacion, validation_steps = steps_validation)
File "C:\Users\Hector\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py", line 108, in _method_wrapper
return method(self, *args, **kwargs)
File "C:\Users\Hector\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py", line 1049, in fit
data_handler = data_adapter.DataHandler(
File "C:\Users\Hector\anaconda3\lib\site-packages\tensorflow\python\keras\engine\data_adapter.py", line 1105, in __init__
self._adapter = adapter_cls(
File "C:\Users\Hector\anaconda3\lib\site-packages\tensorflow\python\keras\engine\data_adapter.py", line 909, in __init__
super(KerasSequenceAdapter, self).__init__(
File "C:\Users\Hector\anaconda3\lib\site-packages\tensorflow\python\keras\engine\data_adapter.py", line 786, in __init__
peek, x = self._peek_and_restore(x)
File "C:\Users\Hector\anaconda3\lib\site-packages\tensorflow\python\keras\engine\data_adapter.py", line 920, in _peek_and_restore
return x[0], x
File "C:\Users\Hector\anaconda3\lib\site-packages\keras_preprocessing\image\iterator.py", line 54, in __getitem__
raise ValueError('Asked to retrieve element {idx}, '
ValueError: Asked to retrieve element 0, but the Sequence has length 0
¿Alguien sabe como puedo solucionar este error? Muchas gracias.