Keras CNN model gives no gradients error during training
I’m trying to create a Convolutional Neural Network model, using an 824 image dataset, for predicting an output value. Problem is that the dataset is quite unstructured, as there are plenty of RGB and grayscale images, and there are no subfolders inside.
I changed them all to grayscale and created train/validation/test splits with the resized images. 338
Then I made a Keras CNN model, but when I try to use fit_generator I have a No gradients provided Value error.
I've attached the colab code. As I’m new in the field of Deep Learning, I would appreciate any help. Thanks in advance.
```
base_dir = '/content/drive/My Drive/Colab/chondro d2 23112016' tif_img = glob.glob("/content/drive/My Drive/Colab/chondro d2 23112016/*.TIF")
Create train/test/validation directories
train_dir = os.path.join(base_dir,'train')
os.mkdir(train_dir)
validation_dir = os.path.join(base_dir,'validation')
os.mkdir(validation_dir)
test_dir = os.path.join(base_dir,'test')
os.mkdir(test_dir)
base_dir = '/content/drive/My Drive/Colab/chondro d2 23112016' tif_img = glob.glob("/content/drive/My Drive/Colab/chondro d2 23112016/*.TIF") train_dir = os.path.join(base_dir,'train')
Images to the folders
TRAIN
filelist = glob.glob(os.path.join(train_dir, "*.TIF")) for f in filelist: os.remove(f)
fnames = [os.path.basename(os.path.normpath(tif_img[i])) for i in range(400)] for fname in fnames: src = os.path.join(base_dir,fname) dst = os.path.join(train_dir,fname) shutil.copyfile(src,dst)
grayscale and resize to (224,224)
for i in range(len(os.listdir(train_dir))): im = Image.open(train_dir + '/'+ os.listdir(train_dir)[i]).convert('L') new_im = im.resize((224,224)) new_im.save(train_dir + '/'+ os.listdir(train_dir)[i])
VALIDATION
filelist = glob.glob(os.path.join(validation_dir, "*.TIF")) for f in filelist: os.remove(f)
fnames = [os.path.basename(os.path.normpath(tif_img[i])) for i in range(400,600)] for fname in fnames: src = os.path.join(base_dir,fname) dst = os.path.join(validation_dir,fname) shutil.copyfile(src,dst)
for i in range(len(os.listdir(validation_dir))): im = Image.open(validation_dir + '/'+ os.listdir(validation_dir)[i]).convert('L') new_im = im.resize((224,224)) new_im.save(validation_dir + '/'+ os.listdir(validation_dir)[i])
TEST
filelist = glob.glob(os.path.join(test_dir, "*.TIF")) for f in filelist: os.remove(f)
fnames = [os.path.basename(os.path.normpath(tif_img[i])) for i in range(600,824)] for fname in fnames: src = os.path.join(base_dir,fname) dst = os.path.join(test_dir,fname) shutil.copyfile(src,dst)
for i in range(len(os.listdir(test_dir))): im = Image.open(test_dir + '/'+ os.listdir(test_dir)[i]).convert('L') new_im = im.resize((224,224)) new_im.save(test_dir + '/'+ os. 338