0

I have a list of numpy arrays which are to be given as input to the neural network model by a generator. However, the shape of numpy arrays can be different (*,1) where * is the dynamic number that is populated for every image. How I can write it in generator? I tried to give this like this in the neural network model.

preds = Input(shape=(None,1),name='preds')

In generator, I am trying to give something like this:

result = np.zeros((batchsize,None,1)) 
for i in range(batch_size):
        result[i,:,:]=predictions

But this is giving me the error that TypeError: 'NoneType' object cannot be interpreted as an integer in declaration of np.zeros(batchsize,None,1). What is the correct way to give dynamic shape for a numpy array.

Sree
  • 973
  • 2
  • 14
  • 32
  • `None` as a dimension is only applicable to `tensorflow/keras` objects, not `numpy` arrays. Usually it's used for the unknown batch size, not the shape of individual images. The size of the training or test datasets can vary, but my impression is that the images themselves must have standard size. Review your network docs if that isn't clear. – hpaulj Nov 12 '19 at 01:35
  • @hpaulj, Actually I am implementing a custom loss function with additional parameters. I am following this https://stackoverflow.com/questions/50124158/keras-loss-function-with-additional-dynamic-parameter link and here one of my function parameters reads the image labels and since my dataset is multi label image dataset, I cannot give any fixed dimension to the number of labels. How can I do it for numpy arrays. – Sree Nov 12 '19 at 03:34
  • Your problem description is not clear or complete. The dimensions of the `results` array must match the dimensions of `predictions`, what ever that is. If that varies with`i`, you cannot assign the values to a numpy array like that. – hpaulj Nov 12 '19 at 03:55

0 Answers0