ValueError: Error when checking target: expected activation_98 to have 3 dimensions, but got array with shape (4, 224, 224, 2)
Opened this issue · 3 comments
samuelTyh commented
Something wrong in the cell below
model.fit_generator(gen_mix, steps_per_epoch=5, epochs=1, verbose=0, callbacks=[tqdm], class_weight=sample_weights)
hearsh commented
Hey even I am having the same problem
patallenDataSci commented
After running:
X, y = next(gen_mix)
y.shape returns:
(4, 224, 224, 2) for me rather than:
(4, 50176, 2) in the original notebook
I am not quite sure what to change in seg_gen_mix or segm_generator to flatten the array into the vector format expected
hxtkyne commented
change like below:
def get_item(self, idx):
slice_r = self.get_slice(self.ri[idx], self.ro)
slice_c = self.get_slice(self.ci[idx], self.co)
x = self.x[idx][slice_r, slice_c]
y = self.y[idx][slice_r, slice_c]
y = np.reshape(y, [self.ro * self.co, -1]) # add this
if self.train and (random.random()>0.5):
y = y[:,::-1]
x = x[:,::-1]
if not self.waldo and np.sum(y)!=0:
return None
return x, to_categorical(y, num_classes=2)