Coder Social home page Coder Social logo

TransUnet for RGB-images? about transunet HOT 9 OPEN

andife avatar andife commented on July 3, 2024 1
TransUnet for RGB-images?

from transunet.

Comments (9)

Beckschen avatar Beckschen commented on July 3, 2024 1

Hello, it seems that the code currently only works on grayscale images. II am interested in processing images with 3 channels (RGB). Has anyone already modified the code accordingly? What do I have to pay attention to?

@andife
Hello, this repo also supports RGB image with 3 channels.

The network is original support 3 channels input (See line 386-387 in vit_seg_modeling.py):
if x.size()[1] == 1:
x = x.repeat(1,3,1,1)

from transunet.

SM-93 avatar SM-93 commented on July 3, 2024

I have a question about running the code. Have you actually ran the code, I mean trained the model and tested the model on their images ? And did you get the same or similar results as in the their paper ?

Thanks

from transunet.

andife avatar andife commented on July 3, 2024

Hello,
it seems that I still have problems to prepare the dataset

So at least the class RandomGenerator cannot be used directly,
because of x, y = image.shape
ValueError: too many values to unpack (expected 2)

I tried the pipeline using it with RGB data, and get the following:

Traceback (most recent call last):
  File "train.py", line 103, in <module>
    trainer[dataset_name](args, net, snapshot_path)
  File "project_TransUNet/TransUNet/trainer.py", line 133, in trainer_owndataset
    for i_batch, sampled_batch in enumerate(trainloader):
  File "anaconda3/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 345, in __next__
    data = self._next_data()
  File anaconda3/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 856, in _next_data
    return self._process_data(data)
  File anaconda3/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 881, in _process_data
    data.reraise()
  File "anaconda3/lib/python3.8/site-packages/torch/_utils.py", line 394, in reraise
    raise self.exc_type(msg)
ValueError: Caught ValueError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "anaconda3/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
    data = fetcher.fetch(index)
  File anaconda3/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File anaconda3/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "project_TransUNet/TransUNet/datasets/dataset_owndataset.py", line 74, in __getitem__
    sample = self.transform(sample)
  File anaconda3/lib/python3.8/site-packages/torchvision/transforms/transforms.py", line 70, in __call__
    img = t(img)
  File project_TransUNet/TransUNet/datasets/dataset_owndataset.py", line 39, in __call__
    x, y   = image.shape
ValueError: too many values to unpack (expected 2)

from transunet.

aneeshgupta42 avatar aneeshgupta42 commented on July 3, 2024

Hello, it seems that the code currently only works on grayscale images. II am interested in processing images with 3 channels (RGB). Has anyone already modified the code accordingly? What do I have to pay attention to?

@andife
Hello, this repo also supports RGB image with 3 channels.

The network is original support 3 channels input (See line 386-387 in vit_seg_modeling.py):
if x.size()[1] == 1:
x = x.repeat(1,3,1,1)

@Beckschen I'm trying to use this model for RGB images. I removed the random rotations (they seemed buggy for RGB images), and instead now get an error on the lines you have mentioned (386-387 in vit_seg_modeling.py). The error is as follows:
RuntimeError: Number of dimensions of repeat dims can not be smaller than number of dimensions of tensor image

from transunet.

andife avatar andife commented on July 3, 2024

Hello,

Can someone point me to the solution?
Does one have working code?

Currently TransUnet expects/uses
shape x: torch.Size([12, 1, 224, 224])
for the synapse dataset.

When I tried to use my files with
RGB-Channel. I got
shape x: torch.Size([12, 1, 3, 736, 736])

Obviously, the dimensions did not fit
.
Think I have to get rid of the '1'
I squeezed the dataset, but then I got the following error:

Traceback (most recent call last):
  File "train.py", line 114, in <module>
    trainer[dataset_name](args, net, snapshot_path)
  File "/home/andife/project_TransUNet/TransUNet/trainer.py", line 223, in trainer_ulm3D
    outputs = model(image_batch)
  File "/home/andife/anaconda3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/andife/project_TransUNet/TransUNet/networks/vit_seg_modeling.py", line 393, in forward
    x, attn_weights, features = self.transformer(x)  # (B, n_patch, hidden)
  File "/home/andife/anaconda3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/andife/project_TransUNet/TransUNet/networks/vit_seg_modeling.py", line 254, in forward
    embedding_output, features = self.embeddings(input_ids)
  File "/home/andife/anaconda3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/andife/project_TransUNet/TransUNet/networks/vit_seg_modeling.py", line 163, in forward
    embeddings = x + self.position_embeddings
RuntimeError: The size of tensor a (2116) must match the size of tensor b (196) at non-singleton dimension 1


from transunet.

Some1OutThere avatar Some1OutThere commented on July 3, 2024

Hello, it seems that the code currently only works on grayscale images. II am interested in processing images with 3 channels (RGB). Has anyone already modified the code accordingly? What do I have to pay attention to?

@andife
Hello, this repo also supports RGB image with 3 channels.
The network is original support 3 channels input (See line 386-387 in vit_seg_modeling.py):
if x.size()[1] == 1:
x = x.repeat(1,3,1,1)

@Beckschen I'm trying to use this model for RGB images. I removed the random rotations (they seemed buggy for RGB images), and instead now get an error on the lines you have mentioned (386-387 in vit_seg_modeling.py). The error is as follows:
RuntimeError: Number of dimensions of repeat dims can not be smaller than number of dimensions of tensor image

Did you fix this? I am also trying to repeat this for RGB images.

from transunet.

PatrickWilliams44 avatar PatrickWilliams44 commented on July 3, 2024

Hello, I have the same problem. Have you solved it?@Some1OutThere

from transunet.

1183498834 avatar 1183498834 commented on July 3, 2024

Hello, it seems that I still have problems to prepare the dataset

So at least the class RandomGenerator cannot be used directly, because of x, y = image.shape ValueError: too many values to unpack (expected 2)

I tried the pipeline using it with RGB data, and get the following:

Traceback (most recent call last):
  File "train.py", line 103, in <module>
    trainer[dataset_name](args, net, snapshot_path)
  File "project_TransUNet/TransUNet/trainer.py", line 133, in trainer_owndataset
    for i_batch, sampled_batch in enumerate(trainloader):
  File "anaconda3/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 345, in __next__
    data = self._next_data()
  File anaconda3/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 856, in _next_data
    return self._process_data(data)
  File anaconda3/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 881, in _process_data
    data.reraise()
  File "anaconda3/lib/python3.8/site-packages/torch/_utils.py", line 394, in reraise
    raise self.exc_type(msg)
ValueError: Caught ValueError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "anaconda3/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
    data = fetcher.fetch(index)
  File anaconda3/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File anaconda3/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "project_TransUNet/TransUNet/datasets/dataset_owndataset.py", line 74, in __getitem__
    sample = self.transform(sample)
  File anaconda3/lib/python3.8/site-packages/torchvision/transforms/transforms.py", line 70, in __call__
    img = t(img)
  File project_TransUNet/TransUNet/datasets/dataset_owndataset.py", line 39, in __call__
    x, y   = image.shape
ValueError: too many values to unpack (expected 2)

I have solved this issue. If the image is a RGB image, the image.shape would be a tuple like (h, w, 3), the original code
x, y = image.shape
is unpacking two elements, but image.shape has three elements. So you can fix it by changing the code like x, y, z = image.shape.

from transunet.

heweapon avatar heweapon commented on July 3, 2024

Hello, it seems that the code currently only works on grayscale images. II am interested in processing images with 3 channels (RGB). Has anyone already modified the code accordingly? What do I have to pay attention to?

@andife
Hello, this repo also supports RGB image with 3 channels.
The network is original support 3 channels input (See line 386-387 in vit_seg_modeling.py):
if x.size()[1] == 1:
x = x.repeat(1,3,1,1)

@Beckschen I'm trying to use this model for RGB images. I removed the random rotations (they seemed buggy for RGB images), and instead now get an error on the lines you have mentioned (386-387 in vit_seg_modeling.py). The error is as follows:
RuntimeError: Number of dimensions of repeat dims can not be smaller than number of dimensions of tensor image

Did you fix this? I am also trying to repeat this for RGB images.

Hello, I had the same problem when running test.py, did you solve it?

from transunet.

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.