Я стараюсь приспособить модель с нейронной сетью. Я написал генератор пакетов, чтобы облегчить процесс. Итак, я получаю такую ошибку ...
ValueError Traceback (most recent call last)
<ipython-input-73-46efbd469429> in <module>()
6 validation_data=siams_generator(test_batch_gen),
7 validation_steps=3,
----> 8 shuffle=True
9 )
10 frames
/content/PDD/pdd/utils/training.py in __get_files_from_names(self, arr)
184 result = np.array(result)
185 result = result.reshape((*arr.shape, *result[0].shape))
--> 186 return result
187
188
ValueError: cannot reshape array of size 64 into shape (2,32,256,256,3)
Это переменные для обучения:
fit_generator(
generator=generator(train_batch_gen),
steps_per_epoch=100,
epochs=150,
verbose=1,
validation_data=generator(test_batch_gen),
validation_steps=30,
shuffle=True
)
Пожалуйста, посмотрите на мой кусок кода ... Это мой код генератора серии:
def shuffle_arrays(*args, axes=None):
'''Axes argument is required
'''
if axes is None:
# if axes weren't pass, then compare 0-axis
sizes = [len(x) for x in args]
else:
assert len(axes) == len(args), "Axes argument should have the same length as args"
sizes = [args[i].shape[axes[i]] for i in range(len(axes))]
assert checkEqual(sizes), "Input arrays must have same sizes"
# permute indices
idx = np.random.permutation(args[0].shape[axes[0]])
return [np.take(args[i], idx, axis=axes[i]) for i in range(len(axes))]
class BatchGenerator(BaseBatchGenerator):
def __init__(self, X, y,
batch_size=42,
flow_from_dir=False,
augment=False,
**kwargs):
self.x = X
self.y = y
self.batch_size = batch_size
self.flow_from_dir = flow_from_dir
self.augment = augment
if flow_from_dir:
# we already have all statistics
self.__dict__.update(kwargs)
else:
self.__count_stats()
# augmentation
if self.augment:
self.__get_distortion_generator()
@classmethod
def from_directory(cls, dirname, batch_size=42, augment=False):
'''Constructor only for images
'''
assert os.path.isdir(dirname), "There is no such directory `%s`" % dirname
X, y = [], []
class_folders = glob(os.path.join(dirname, "*", ""))
n_classes = len(class_folders)
samples_per_class = np.zeros(n_classes, dtype=np.int32)
class_idx = [None]*n_classes
for i, folder in enumerate(class_folders):
img_fnames = glob(os.path.join(dirname, folder, '*.jpg'))
# add all image files with other extensions
for ext in ["*.png", "*jpeg"]:
img_fnames.extend(glob(os.path.join(dirname, folder, ext)))
# add filenames and corresponding labels to array
X.extend(img_fnames)
y.extend([i]*len(img_fnames))
samples_per_class[i] = len(img_fnames)
# split sorted indices on classes
if i == 0:
class_idx[i] = np.arange(len(img_fnames))
else:
low = sum(samples_per_class[:i])
high = low + samples_per_class[i]
class_idx[i] = np.arange(low, high, dtype=np.int32)
# transform to arrays for convenience
X = np.array(X)
y = np.array(y, dtype=np.int8)
# call __init__
return cls(X, y, batch_size, flow_from_dir=True,
augment=augment,
# kwargs
n_classes=n_classes,
samples_per_class=samples_per_class,
class_idx=class_idx)
def __get_files_from_names(self, arr):
result = [None]*arr.size
# read all files
for i, x in enumerate(np.nditer(arr)):
result[i] = imread(str(x)) / 255.
if self.augment:
result[i] = self.random_distortion(result[i])
result = np.array(result)
result = result.reshape((*arr.shape, *result[0].shape))
return result
Формат фотографий (256 256) с импортом в оттенки серого. Пожалуйста, помогите мне!:)