Skip to content
Advertisement

InvalidArgumentError: StringToNumberOp could not correctly convert string

I am trying to extract the labels from a file path of the form:

JavaScript

The labels are 26, 0 and 3 in the file name

first I create a list dataset:

JavaScript

then I define a function that reads the image and gets the labels and use .map() on list_ds

JavaScript

when I print some one of the labels as a sanity check I get this (1):

JavaScript

but when I apply .batch() on ds and then try to print all the labels from the dataset, most of the labels are printed but then this error shows up:

JavaScript

any ideas what might be causing this?

also regarding (1), I was expecting the output tensor to be tf.Tensor([1, 0, 2], shape=(3,), dtype=int64) and not tf.Tensor([1 0 2], shape=(3,), dtype=int64). what kind of tensor is this?

Advertisement

Answer

It turns out the error was caused by a few files that were missing the third label from their filename and the tf.strings.to_number() method was trying to convert a substring of the form ‘20170119181310597.jpg.chip.jpg’ to a number.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement