При выполнении этого кода:
train_datagen = data_generator(train_samples, batch_size=32)
x, y = next(train_datagen)
print('x_shape: ', x.shape)
print('labels shape: ', y.shape)
print('labels: ', y)
Я получил эту ошибку:
---------------------------------------------------------------------------
error Traceback (most recent call last)
<ipython-input-23-f5b1e52beeb7> in <module>()
2 train_datagen = data_generator(train_samples, batch_size=32)
3
----> 4 x, y = next(train_datagen)
5 print('x_shape: ', x.shape)
6 print('labels shape: ', y.shape)
1 frames
<ipython-input-9-8b6cad19bbdf> in preprocessing(img, new_height, new_width)
1 # Function to define size of images and normalize pixels
2 def preprocessing(img, new_height, new_width):
----> 3 img = cv2.resize(img,(new_height, new_width))
4 img = img/255
5 return img
Функция data_generator
определяется следующим образом:
def data_generator(samples, batch_size, shuffle_data = True, resize=224):
num_samples = len(samples)
while True:
random.shuffle(samples)
for offset in range(0, num_samples, batch_size):
batch_samples = samples[offset: offset + batch_size]
X_train = []
y_train = []
for batch_sample in batch_samples:
img_name = batch_sample[0]
label = batch_sample[1]
img = cv2.imread(os.path.join(root_dir, img_name))
#img, label = preprocessing(img, label, new_height=224, new_width=224, num_classes=37)
img = preprocessing(img, new_height=224, new_width=224)
label = my_onehot_encoded(label)
X_train.append(img)
y_train.append(label)
X_train = np.array(X_train)
y_train = np.array(y_train)
yield X_train, y_train
train_samples
определяется как:
train_samples = load_samples(train_data_path)
Функция load_samples
определяется как:
def load_samples(csv_file):
data = pd.read_csv(os.path.join('/content/gdrive/My Drive/data/2017-IWT4S-CarsReId_LP-dataset/', csv_file))
data = data[['FileName', 'Label']]
file_names = list(data.iloc[:,0])
labels = list(data.iloc[:,1])
samples = []
for samp, lab in zip(file_names, labels):
samples.append([samp, lab])
return samples
Кто-нибудь знает, что пошло не так?