0
votes

So, I am again trying to run this Inception v3 fine tuning with keras, i think there is some problem with the arrays. I've already seen the other posts on these topics, but now i don´t know what to do. I don't have a lot of experience. So any help would be appreciated.

Here is the entire code https://github.com/c3s4grod/PecuScope

And this is the error that appears:

Traceback (most recent call last):

File "C:\Users\Shangai\AppData\Local\conda\conda\envs\PSAI\lib\site-packages\keras\utils\data_utils.py", line 578, in get inputs = self.queue.get(block=True).get() File "C:\Users\Shangai\AppData\Local\conda\conda\envs\PSAI\lib\multiprocessing\pool.py", line 644, in get raise self._value File "C:\Users\Shangai\AppData\Local\conda\conda\envs\PSAI\lib\multiprocessing\pool.py", line 119, in worker result = (True, func(*args, **kwds)) File "C:\Users\Shangai\AppData\Local\conda\conda\envs\PSAI\lib\site-packages\keras\utils\data_utils.py", line 401, in get_index return _SHARED_SEQUENCES[uid][i] File "C:\Users\Shangai\AppData\Local\conda\conda\envs\PSAI\lib\site-packages\keras\preprocessing\image.py", line 1034, in getitem return self._get_batches_of_transformed_samples(index_array) File "C:\Users\Shangai\AppData\Local\conda\conda\envs\PSAI\lib\site-packages\keras\preprocessing\image.py", line 1442, in _get_batches_of_transformed_samples batch_x[i] = x ValueError: could not broadcast input array from shape (8,8,3) into shape (8,8,2048,3)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):

File "C:/Users/Shangai/PycharmProjects/PSai/INCEPTION.py", line 234, in validation_steps=steps_test) File "C:\Users\Shangai\AppData\Local\conda\conda\envs\PSAI\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper return func(*args, **kwargs) File "C:\Users\Shangai\AppData\Local\conda\conda\envs\PSAI\lib\site-packages\keras\models.py", line 1315, in fit_generator initial_epoch=initial_epoch) File "C:\Users\Shangai\AppData\Local\conda\conda\envs\PSAI\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper return func(*args, **kwargs) File "C:\Users\Shangai\AppData\Local\conda\conda\envs\PSAI\lib\site-packages\keras\engine\training.py", line 2194, in fit_generator generator_output = next(output_generator) File "C:\Users\Shangai\AppData\Local\conda\conda\envs\PSAI\lib\site-packages\keras\utils\data_utils.py", line 584, in get six.raise_from(StopIteration(e), e) File "", line 2, in raise_from StopIteration: could not broadcast input array from shape (8,8,3) into shape (8,8,2048,3)

1

1 Answers

1
votes

It looks like your input tensor has not the correct size. In general broadcasting only works if both arrays / tensors have the same number of dimensions. In your case that is not true:

8 8 3       -> dim = 3
8 8 2048 3  -> dim = 4

You need to expand the first array and add an axis with size 1 at the right position:

8 8 1    3
8 8 2048 3

Now the sizes of each axis match and for the 3. dimension broadcasting is possible. To achieve this you can use the newaxis- or None-notation.

import numpy as np
A = np.ones((8, 8, 3))
B = np.ones((8, 8, 2048, 3))
C = A + B # Fails
A = A[:, :, np.newaxis, :]
C = A + B # Works

Another possibility is to use the function numpy.expand_dims. The same notation is available for tensors in keras / tensorflow (i.e. tensorflow.newaxis, tensorflow.expand_dims).