How to use prototypes.pth that only contains a single class?
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 ?
See here: https://github.com/mlzxy/devit/issues/8#issuecomment-1754145097
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.pywith 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?
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.pywith 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)