sainatarajan / U-Net

A simple U-Net implementation for custom dataset. Just create required folders and place the images and then start training.
20 stars 6 forks source link

Training on images with 4 channels #16

Open cspearl opened 3 years ago

cspearl commented 3 years ago

Hi I am trying to train the model on a custom dataset which has images in 4 channels. RGB images and NIR images could you help me out as to how should I read my data and start training where do i need to do changes in the code?

sainatarajan commented 3 years ago

Hi, you could change the input channels to 4 instead of 3 in this line. You can save your files as png images as described in the readme. Do note that this repo doesn't work for multiclass segmentation.

I would instead suggest you have a look at this keras repo or this one if you are working on pytorch.

You can get extremely good results if you use either of the above 2 repos.

cspearl commented 3 years ago

I am working with binary segmentation (one class and one background) so your repo would work fine I believe? I have changed the input channels to 4 in unet.py. How should I change data.py if you could please guide me.

cspearl commented 3 years ago

I was training with images of one size(512,512,4) and tried to test the model predictions on images of another size(1024,1024,3) but it is giving an error as to saying : I think we can test on images of any size after we have trained the model Traceback (most recent call last): File "unet.py", line 167, in myunet.train() File "unet.py", line 134, in train imgs_mask_test = model.predict(imgs_test, batch_size=1, verbose=1) File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/keras/engine/training.py", line 908, in predict use_multiprocessing=use_multiprocessing) File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/keras/engine/training_arrays.py", line 716, in predict x, check_steps=True, steps_name='steps', steps=steps) File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/keras/engine/training.py", line 2471, in _standardize_user_data exception_prefix='input') File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/keras/engine/training_utils.py", line 572, in standardize_input_data str(data_shape)) ValueError: Error when checking input: expected input_2 to have shape (512, 512, 4) but got array with shape (1024, 1024, 3)