Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only 4D input tensorsare supported (got 3D) #32

Open
Irennnne opened this issue Jul 11, 2024 · 1 comment
Open

Only 4D input tensorsare supported (got 3D) #32

Irennnne opened this issue Jul 11, 2024 · 1 comment

Comments

@Irennnne
Copy link

Irennnne commented Jul 11, 2024

I got this problem when I tried to inference on my own dataset. Could you give me some advice? Thank you!

Traceback (most recent call last):
  File "train_net.py", line 317, in <module>
    launch(
  File "/home/anaconda3/envs/kksan/lib/python3.8/site-packages/detectron2/engine/launch.py", line 67, in launch
    mp.spawn(
  File "/home/anaconda3/envs/kksan/lib/python3.8/site-packages/torch/multiprocessing/spawn.py", line 240, in spawn
    return start_processes(fn, args, nprocs, join, daemon, start_method='spawn')
  File "/home/anaconda3/envs/kksan/lib/python3.8/site-packages/torch/multiprocessing/spawn.py", line 198, in start_processes
    while not context.join():
  File "/home/anaconda3/envs/kksan/lib/python3.8/site-packages/torch/multiprocessing/spawn.py", line 160, in join
    raise ProcessRaisedException(msg, error_index, failed_process.pid)
torch.multiprocessing.spawn.ProcessRaisedException: 

-- Process 1 terminated with the following error:
Traceback (most recent call last):
  File "/home/anaconda3/envs/kksan/lib/python3.8/site-packages/torch/multiprocessing/spawn.py", line 69, in _wrap
    fn(i, *args)
  File "/home/anaconda3/envs/kksan/lib/python3.8/site-packages/detectron2/engine/launch.py", line 126, in _distributed_worker
    main_func(*args)
  File "/home/data4/jieming/new_open_voc/CAT-Seg/train_net.py", line 302, in main
    res = Trainer.test(cfg, model)
  File "/home/anaconda3/envs/kksan/lib/python3.8/site-packages/detectron2/engine/defaults.py", line 608, in test
    results_i = inference_on_dataset(model, data_loader, evaluator)
  File "/home/anaconda3/envs/kksan/lib/python3.8/site-packages/detectron2/evaluation/evaluator.py", line 158, in inference_on_dataset
    outputs = model(inputs)
  File "/home/anaconda3/envs/kksan/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/data4/jieming/new_open_voc/CAT-Seg/cat_seg/cat_seg_model.py", line 165, in forward
    return self.inference_sliding_window(batched_inputs)
  File "/home/anaconda3/envs/kksan/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "/home/data4/jieming/new_open_voc/CAT-Seg/cat_seg/cat_seg_model.py", line 249, in inference_sliding_window
    image = rearrange(unfold(image), "(C H W) L-> L C H W", C=3, H=kernel)
  File "/home/anaconda3/envs/kksan/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/anaconda3/envs/kksan/lib/python3.8/site-packages/torch/nn/modules/fold.py", line 294, in forward
    return F.unfold(input, self.kernel_size, self.dilation,
  File "/home/anaconda3/envs/kksan/lib/python3.8/site-packages/torch/nn/functional.py", line 4666, in unfold
    raise NotImplementedError("Input Error: Only 4D input Tensors are supported (got {}D)".format(input.dim()))
NotImplementedError: Input Error: Only 4D input Tensors are supported (got 3D)
@Qiming-Huang
Copy link

Qiming-Huang commented Jul 22, 2024

@Irennnne
Hi, I got the same issue, and solved it this way:

Modify the codes in cat_seg_model.py, lines 194,195 to:

# image = F.interpolate(images[0].unsqueeze(0), size=out_res, mode='bilinear', align_corners=False).squeeze()
# image = rearrange(unfold(image), "(C H W) L-> L C H W", C=3, H=kernel)

image = F.interpolate(images[0].unsqueeze(0), size=out_res, mode='bilinear', align_corners=False)
image = rearrange(unfold(image).squeeze(), "(C H W) L-> L C H W", C=3, H=kernel) 

and the code in cat_seg_model.py to:

# outputs = fold(outputs.flatten(1).T) / fold(unfold(torch.ones([1] + out_res, device=self.device)))

outputs = fold(outputs.flatten(1).T.unsqueeze(0)) / fold(unfold(torch.ones([1] + out_res, device=self.device).unsqueeze(0)))

Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants