1

I am trying to train a model. Training Labels are stored in training_labels which is a <class 'numpy.ndarray'> . Each item in labels array has the following format of a 2d numpy array with shape of M * 5. M has a different value for each training example.( for example (8, 5) for first training example, (3, 5) for second training example).

I need to convert my labels to tensors and then use padding to have kind of a rectangular tensors.

Now i try to use tensorflow.convert_to_tensor to try to convert the training_labels to tensors, but it throws a ValueError exception like this :

ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray).

Now when i try to convert each of the training_labels to tensors individually,(for example

tensorflow.convert_to_tensor(training_labels[0]))

it works perfectly since it is just a one 2d numpy array.

Now how can i convert my training_labels to tensors?

Me Bottle O Scrumpy
  • 266
  • 1
  • 3
  • 12
  • 1
    You can't. While numpy can make an object dtype array from arrays that vary in shape (with a `ragged array` warning), `tensorflow` cannot convert that to a `tensor`.It's up to you do decide and do the padding before hand. – hpaulj Oct 26 '21 at 19:47
  • @hpaulj So before i start the training process i should try to pad the labels to fixed sizes like `F * 5` then convert the labels easily to tensors. but wouldn't it cause a problem when the there are more than `F` objects in the picture? – Me Bottle O Scrumpy Oct 26 '21 at 20:03
  • 1
    How you adjust the inputs to a consistent size depends on the model. I won't presume to tell you what is the right way. That's between you and the model developer. – hpaulj Oct 26 '21 at 20:18
  • 1
    Does [this](https://stackoverflow.com/a/60750937/14290681) reference help you to solve this issue? –  Jan 12 '22 at 11:56

0 Answers0