0

New to Tensorflow, and I want to achieve something fairly specific.

I have a csv in which I have images with space separated pixel values between 0 and 255 in a column. So that would look like so:

Image
255 255 ... 255
199 199 ... 199
100 100 ... 100

I want to apply some convolutional neural nets on them. So I'd like to end up with a Tensor like this:

[[255, 255, 255], [199, 199, 199], [100, 100, 100]]

I am sure a possibility would be to read in in a string tensor, and then maybe apply tf.string_to_number(tf.string_split(.., delimiter=' ')),

img = ... // string tensor from csv
img = tf.string_to_number(tf.string_split(img, ' '))

But I get the following error:

Shape must be rank 1 but is rank 2 for 'StringSplit' (op: 'StringSplit') with input shapes: [?,1], [].

I just started TensorFlow, my string tensor is a simple column, so its shape should be (?,) rather no? Otherwise, is it the right way to look at this?

Cheers

Al Wld
  • 869
  • 7
  • 19
  • 1
    You can try to solve the problem from _outside_ Tensorflow by reading in the file using Python's excellent `csv` module and converting that to image array before passing it to Tensorflow. – musically_ut Apr 27 '17 at 21:54

1 Answers1

1

Just because your images in such a strange format, I assume that this is just a learning project.

In this case I do not think that it makes sense to do this in TF. If I were you I would create a function that reads a csv file in pandas, then grab the numpy array and save it as image. There are many ways to do this, and a simple search will give you many examples. After this I will iterate over all csv files, save all the images and forget about this step forever.

Community
  • 1
  • 1
Salvador Dali
  • 214,103
  • 147
  • 703
  • 753