jakeret / tf_unet

Generic U-Net Tensorflow implementation for image segmentation
GNU General Public License v3.0
1.9k stars 748 forks source link

Format of input? #5

Closed sansinghsanjay closed 7 years ago

sansinghsanjay commented 7 years ago

I have a numpy (.npy) file having data of 564 image files, shape is [564, 420, 580] and same for their masks, [564, 420, 580].

I am saving these numpy objects in a h5py file and then passing it like:

dataset_file = h5py.File(source_path, 'r')
generator = Generator(1, dataset_file)

but getting following errors: AttributeError: 'int' object has no attribute 'encode' at line: 41 of radio_util.py: with h5py.File(self.files[self.file_idx], "r") as fp

Please help me...

sansinghsanjay commented 7 years ago

I worked with different approaches and got answer of my question.

Here, we have to pass pair of image and its mask in h5 file. So, every pair of image and mask have an h5 file. We have to store all these h5 files in a directory and finally pass the path of this directory in Generator function.

sansinghsanjay commented 7 years ago

Can you please explain the format and shape in which input have to be passed in Generator function. I have 564 images of shape [420, 580] and similarly 564 masks of shape [420, 580].

Currently I tried to pass these images and their masks in hdf5 files. So every pair of image and mask forms a hdf5 file with "data" for image and "mask" for mask. But still I am getting error: "Computed output size would be negative" at following line of store_prediction() function:

prediction = sess.run(net.predicter, feed_dict={net.x: batch_x,net.y: batch_y,net.keep_prob: 1.})

Thanks..

jakeret commented 7 years ago

Hi Sanjay Singh The loading process is often very specific to the dataset. I therefore never anticipated that the Generator class is the scripts folder would be reused for another project. I would recommend that you write your own loading code as it will give you the maximum flexiblity. Have a look at my implementations in the script folder or this examples that I wrote: https://gist.github.com/jakeret/cd1e8b51009b995c38b44101c38ad831

For a binary classification problem with gray scale images tf_unet expects the format

data = np.zeros((n, nx, ny, 1))
mask = np.zeros((n, nx, ny, 2))

n is the batch_size and 1 because of the gray scale and 2 because of the one-hot encoding that is required.

Hope this helps

sansinghsanjay commented 7 years ago

Thanks a lot... I am working with this package and get back to you if I faced any more issues..

Thanks..