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

How to use prototypes.pth that only contains a single class? #39

Open
kaninaba94 opened this issue Jan 18, 2024 · 3 comments
Open

How to use prototypes.pth that only contains a single class? #39

kaninaba94 opened this issue Jan 18, 2024 · 3 comments

Comments

@kaninaba94
Copy link

I want to train a few shot object detector to recognize only a single class, which I built prototypes for using this blueprint: https://github.com/mlzxy/devit/blob/main/demo/build_prototypes.ipynb

Now when I run python demo/demo.py with some other images of the same class as input, I get an error, presumably because I only have a single class in my prototypes:

File "demo/demo.py", line 272, in <module>
    fire.Fire(main)
  File "/home/appuser/.local/lib/python3.8/site-packages/fire/core.py", line 141, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/home/appuser/.local/lib/python3.8/site-packages/fire/core.py", line 475, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
  File "/home/appuser/.local/lib/python3.8/site-packages/fire/core.py", line 691, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "demo/demo.py", line 221, in main
    output = model(batched_inputs)[0]
  File "/home/appuser/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/appuser/devit/demo/../detectron2/modeling/meta_arch/devit.py", line 1168, in forward
    other_classes = interpolate(other_classes, self.T, mode='linear') # (Nxclasses) x spatial x T
  File "/home/appuser/devit/demo/../detectron2/modeling/meta_arch/devit.py", line 86, in interpolate
    return F.interpolate(seq, T, mode=mode) 
  File "/home/appuser/.local/lib/python3.8/site-packages/torch/nn/functional.py", line 3945, in interpolate
    return torch._C._nn.upsample_linear1d(input, output_size, align_corners, scale_factors)
RuntimeError: Input and output sizes should be greater than 0, but got input (W: 0) and output (W: 128)

Any hunch as to how I can solve this? Might the issue be that I did not explicitly train few shot object detector using https://github.com/mlzxy/devit/blob/main/tools/train_net.py ?

@Rivoks
Copy link

Rivoks commented Apr 26, 2024

See here: #8 (comment)

@renshouyu
Copy link

I want to train a few shot object detector to recognize only a single class, which I built prototypes for using this blueprint: https://github.com/mlzxy/devit/blob/main/demo/build_prototypes.ipynb

Now when I run python demo/demo.py with some other images of the same class as input, I get an error, presumably because I only have a single class in my prototypes:

File "demo/demo.py", line 272, in <module>
    fire.Fire(main)
  File "/home/appuser/.local/lib/python3.8/site-packages/fire/core.py", line 141, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/home/appuser/.local/lib/python3.8/site-packages/fire/core.py", line 475, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
  File "/home/appuser/.local/lib/python3.8/site-packages/fire/core.py", line 691, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "demo/demo.py", line 221, in main
    output = model(batched_inputs)[0]
  File "/home/appuser/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/appuser/devit/demo/../detectron2/modeling/meta_arch/devit.py", line 1168, in forward
    other_classes = interpolate(other_classes, self.T, mode='linear') # (Nxclasses) x spatial x T
  File "/home/appuser/devit/demo/../detectron2/modeling/meta_arch/devit.py", line 86, in interpolate
    return F.interpolate(seq, T, mode=mode) 
  File "/home/appuser/.local/lib/python3.8/site-packages/torch/nn/functional.py", line 3945, in interpolate
    return torch._C._nn.upsample_linear1d(input, output_size, align_corners, scale_factors)
RuntimeError: Input and output sizes should be greater than 0, but got input (W: 0) and output (W: 128)

Any hunch as to how I can solve this? Might the issue be that I did not explicitly train few shot object detector using https://github.com/mlzxy/devit/blob/main/tools/train_net.py ?

Hello, have you solved this problem?

@pooya-github
Copy link

pooya-github commented Dec 29, 2024

I want to train a few shot object detector to recognize only a single class, which I built prototypes for using this blueprint: https://github.com/mlzxy/devit/blob/main/demo/build_prototypes.ipynb
Now when I run python demo/demo.py with some other images of the same class as input, I get an error, presumably because I only have a single class in my prototypes:

File "demo/demo.py", line 272, in <module>
    fire.Fire(main)
  File "/home/appuser/.local/lib/python3.8/site-packages/fire/core.py", line 141, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/home/appuser/.local/lib/python3.8/site-packages/fire/core.py", line 475, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
  File "/home/appuser/.local/lib/python3.8/site-packages/fire/core.py", line 691, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "demo/demo.py", line 221, in main
    output = model(batched_inputs)[0]
  File "/home/appuser/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/appuser/devit/demo/../detectron2/modeling/meta_arch/devit.py", line 1168, in forward
    other_classes = interpolate(other_classes, self.T, mode='linear') # (Nxclasses) x spatial x T
  File "/home/appuser/devit/demo/../detectron2/modeling/meta_arch/devit.py", line 86, in interpolate
    return F.interpolate(seq, T, mode=mode) 
  File "/home/appuser/.local/lib/python3.8/site-packages/torch/nn/functional.py", line 3945, in interpolate
    return torch._C._nn.upsample_linear1d(input, output_size, align_corners, scale_factors)
RuntimeError: Input and output sizes should be greater than 0, but got input (W: 0) and output (W: 128)

Any hunch as to how I can solve this? Might the issue be that I did not explicitly train few shot object detector using https://github.com/mlzxy/devit/blob/main/tools/train_net.py ?

Hello, have you solved this problem?

Hi,

In the file demo.py modify the code in this part:

if category_space is not None:
category_space = torch.load(category_space)
model.label_names = category_space['label_names']
model.test_class_weight = category_space['prototypes'].to(device)

to:

if category_space is not None:
category_space = torch.load(category_space)
if len(category_space["label_names"]) < 2:
category_space["label_names"].append("blank")
real_prototypes = category_space["prototypes"]
blank_prototypes = torch.zeros(1, 1024)
category_space["prototypes"] = torch.cat((real_prototypes, blank_prototypes), 0)
model.label_names = category_space["label_names"]
model.test_class_weight = category_space["prototypes"].to(device)

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

4 participants