Giter Club home page Giter Club logo

Comments (9)

milesial avatar milesial commented on May 17, 2024

Are your images in dir_img in colors (RGB) ? It seems that after the loading the images don't have 3 dimensions. Can you check the shape of im ?

from pytorch-unet.

I-CANT-CODE avatar I-CANT-CODE commented on May 17, 2024

my pictures are all black and white but I am not sure if they are formatted as RGB

from pytorch-unet.

milesial avatar milesial commented on May 17, 2024

that's the problem, I think they are loaded with only 1 channel so the shape is HxW where it should be CxHxW. You can try to change the code you mentionned to return np.expand_dims(np.array(im),axis=2), np.array(mask).

And if you haven't, you need to change n_channels to 1 in the UNet creation.

from pytorch-unet.

I-CANT-CODE avatar I-CANT-CODE commented on May 17, 2024

Made the changes you mentioned and still am getting

Starting training:
    Epochs: 5
    Batch size: 10
    Learning rate: 0.1
    Training size: 1900
    Validation size: 100
    Checkpoints: True
    CUDA: True

Starting epoch 1/5.
Traceback (most recent call last):
File "train.py", line 139, in
img_scale=args.scale)
File "train.py", line 64, in train_net
for i, b in enumerate(batch(train, batch_size)):
File "/home/users/rssadre/RAPIDS-IDREAM/Pytorch-UNet/utils/utils.py", line 37, in batch
for i, t in enumerate(iterable):
File "/home/users/rssadre/RAPIDS-IDREAM/Pytorch-UNet/utils/utils.py", line 17, in hwc_to_chw
return np.transpose(img, axes=[2, 0, 1])
File "/home/users/rssadre/anaconda3/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 639, in transpose
return _wrapfunc(a, 'transpose', axes)
File "/home/users/rssadre/anaconda3/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 56, in _wrapfunc
return getattr(obj, method)(*args, **kwds)
ValueError: axes don't match array

from pytorch-unet.

milesial avatar milesial commented on May 17, 2024

In the hwc_to_chw function before the line 17, can you print the shape of img (img.shape) and give it to me ? It should have 3 dimensions, no less.

from pytorch-unet.

JoanHHH avatar JoanHHH commented on May 17, 2024

@milesial Hi, thanks for sharing. My image shape is H × W, how should I modify the code?

from pytorch-unet.

JoanHHH avatar JoanHHH commented on May 17, 2024

@milesial I added img = np.reshape(img,img.shape+(1,)) in hwc_to_chw(), the error disappeared, but I don't know if it really solved the problem

from pytorch-unet.

milesial avatar milesial commented on May 17, 2024

Your image should be H x W * C, with C a "dummy" dimension in your case because there is only one channel. The code you cited adds this dimension so it should be OK now.

from pytorch-unet.

yangyang9706 avatar yangyang9706 commented on May 17, 2024

hello, I have the same problem with you. My dataset is also the same with you . And I modify the mode as your discussion above. But I get the problem
Starting training:
Epochs: 5
Batch size: 10
Learning rate: 0.1
Training size: 2204
Validation size: 116
Checkpoints: True
CUDA: True

Starting epoch 1/5.
(200, 125, 1)
(197, 125, 1)
(197, 125, 1)
(200, 125, 1)
(200, 125, 1)
(197, 125, 1)
(197, 125, 1)
(197, 125, 1)
(200, 125, 1)
(200, 125, 1)
Traceback (most recent call last):
File "train.py", line 141, in
img_scale=args.scale)
File "train.py", line 67, in train_net
imgs = np.array([i[0] for i in b]).astype(np.float32)
ValueError: could not broadcast input array from shape (200,125) into shape (1)

How should I deal with these?
Thank you.

from pytorch-unet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.