Hello,
Thanks for your contribution, paper and code.
My goal is
I am trying to visualize the model with Tensorboard and I cannot make it work. So my question is, how did visualize for PSTR development, please :grin:.
What did I try
Basically, I load the config file from CUHK dataset then I build the dataset and dataloader with your builder functions. Then the model is imported and I got a new version with the MMDataParallel
function.
Finally, I initialize a writer = SummaryWriter(...)
and I try to add the graph of the model to my logs by writing: writer.add_graph(model, data)
(where data
is the first batch from my Dataloader object). Here a minimal code (greatly inspired by your test script, withouh PATH variables and imports):
cfg = Config.fromfile(CONFIGPATH)
dataset = build_dataset(cfg.data.test)
data_loader = build_dataloader(
dataset=dataset,
samples_per_gpu=1,
workers_per_gpu=cfg.data.workers_per_gpu,
dist=False,
shuffle=False,
)
model = build_detector(cfg.model, test_cfg=cfg.get("test_cfg"))
checkpoint = load_checkpoint(
model,
str(MODELPATH),
map_location="cpu",
)
model.CLASSES = dataset.CLASSES
model = MMDataParallel(model, device_ids=[0])
What happened
Tensorboard does not like that there are additional meta data inside the input. But if I only write writer.add_graph(model, data['img'])
then the model cannot infers, obviously. Here the output
loading annotations into memory...
Done (t=0.19s)
creating index...
index created!
3
/PSTR/mmcv/mmcv/cnn/bricks/transformer.py:341: UserWarning: The arguments `feedforward_channels` in BaseTransformerLayer has been deprecated, now you should set `feedforward_channels` and other FFN related arguments to a dict named `ffn_cfgs`.
warnings.warn(
/PSTR/mmcv/mmcv/cnn/bricks/transformer.py:341: UserWarning: The arguments `ffn_dropout` in BaseTransformerLayer has been deprecated, now you should set `ffn_drop` and other FFN related arguments to a dict named `ffn_cfgs`.
warnings.warn(
/PSTR/mmcv/mmcv/cnn/bricks/transformer.py:341: UserWarning: The arguments `ffn_num_fcs` in BaseTransformerLayer has been deprecated, now you should set `num_fcs` and other FFN related arguments to a dict named `ffn_cfgs`.
warnings.warn(
/PSTR/mmcv/mmcv/cnn/bricks/transformer.py:92: UserWarning: The arguments `dropout` in MultiheadAttention has been deprecated, now you can separately set `attn_drop`(float), proj_drop(float), and `dropout_layer`(dict)
warnings.warn('The arguments `dropout` in MultiheadAttention '
load checkpoint from local path: pstr_r50_cuhk-2fd8c1d2.pth
2022-05-25 12:55:34,661 - root - INFO - DeformConv2dPack neck.convs.0 is upgraded to version 2.
2022-05-25 12:55:34,661 - root - INFO - DeformConv2dPack neck.convs.1 is upgraded to version 2.
2022-05-25 12:55:34,662 - root - INFO - DeformConv2dPack neck.convs.2 is upgraded to version 2.
Tracer cannot infer type of ({'img_metas': [DataContainer([[{'filename': './data/cuhk/Image/SSM/s15535.jpg', 'ori_filename': 's15535.jpg', 'ori_shape': (450, 800, 3), 'img_shape': (844, 1500, 3), 'pad_shape': (844, 1500, 3), 'scale_factor': array([1.875 , 1.8755555, 1.875 , 1.8755555], dtype=float32), 'flip': False, 'flip_direction': None, 'img_norm_cfg': {'mean': array([123.675, 116.28 , 103.53 ], dtype=float32), 'std': array([58.395, 57.12 , 57.375], dtype=float32), 'to_rgb': True}}]])], 'img': [tensor([[[[-2.1179, -2.1179, -2.1179, ..., -2.1179, -2.1179, -2.1179],
[-2.1179, -2.1179, -2.1179, ..., -2.1179, -2.1179, -2.1179],
[-2.1179, -2.1179, -2.1179, ..., -2.1179, -2.1179, -2.1179],
...,
[-2.1179, -2.1179, -2.1179, ..., -2.1179, -2.1179, -2.1179],
[-2.1179, -2.1179, -2.1179, ..., -2.1179, -2.1179, -2.1179],
[-2.1179, -2.1179, -2.1179, ..., -2.1179, -2.1179, -2.1179]],
[[-2.0357, -2.0357, -2.0357, ..., -2.0357, -2.0357, -2.0357],
[-2.0357, -2.0357, -2.0357, ..., -2.0357, -2.0357, -2.0357],
[-2.0357, -2.0357, -2.0357, ..., -2.0357, -2.0357, -2.0357],
...,
[-2.0357, -2.0357, -2.0357, ..., -2.0357, -2.0357, -2.0357],
[-2.0357, -2.0357, -2.0357, ..., -2.0357, -2.0357, -2.0357],
[-2.0357, -2.0357, -2.0357, ..., -2.0357, -2.0357, -2.0357]],
[[-1.8044, -1.8044, -1.8044, ..., -1.8044, -1.8044, -1.8044],
[-1.8044, -1.8044, -1.8044, ..., -1.8044, -1.8044, -1.8044],
[-1.8044, -1.8044, -1.8044, ..., -1.8044, -1.8044, -1.8044],
...,
[-1.8044, -1.8044, -1.8044, ..., -1.8044, -1.8044, -1.8044],
[-1.8044, -1.8044, -1.8044, ..., -1.8044, -1.8044, -1.8044],
[-1.8044, -1.8044, -1.8044, ..., -1.8044, -1.8044, -1.8044]]]])]},)
:Could not infer type of list element: Only tensors and (possibly nested) tuples of tensors, lists, or dictsare supported as inputs or outputs of traced functions, but instead got value of type DataContainer.
Error occurs, No graph saved
Traceback (most recent call last):
File "/code/PSTR/visualise.py", line 41, in <module>
writer.add_graph(model, data)
File "/opt/conda/lib/python3.8/site-packages/torch/utils/tensorboard/writer.py", line 723, in add_graph
self._get_file_writer().add_graph(graph(model, input_to_model, verbose))
File "/opt/conda/lib/python3.8/site-packages/torch/utils/tensorboard/_pytorch_graph.py", line 292, in graph
raise e
File "/opt/conda/lib/python3.8/site-packages/torch/utils/tensorboard/_pytorch_graph.py", line 286, in graph
trace = torch.jit.trace(model, args)
File "/opt/conda/lib/python3.8/site-packages/torch/jit/_trace.py", line 733, in trace
return trace_module(
File "/opt/conda/lib/python3.8/site-packages/torch/jit/_trace.py", line 934, in trace_module
module._c._create_method_from_trace(
RuntimeError: Tracer cannot infer type of ({'img_metas': [DataContainer([[{'filename': './data/cuhk/Image/SSM/s15535.jpg', 'ori_filename': 's15535.jpg', 'ori_shape': (450, 800, 3), 'img_shape': (844, 1500, 3), 'pad_shape': (844, 1500, 3), 'scale_factor': array([1.875 , 1.8755555, 1.875 , 1.8755555], dtype=float32), 'flip': False, 'flip_direction': None, 'img_norm_cfg': {'mean': array([123.675, 116.28 , 103.53 ], dtype=float32), 'std': array([58.395, 57.12 , 57.375], dtype=float32), 'to_rgb': True}}]])], 'img': [tensor([[[[-2.1179, -2.1179, -2.1179, ..., -2.1179, -2.1179, -2.1179],
[-2.1179, -2.1179, -2.1179, ..., -2.1179, -2.1179, -2.1179],
[-2.1179, -2.1179, -2.1179, ..., -2.1179, -2.1179, -2.1179],
...,
[-2.1179, -2.1179, -2.1179, ..., -2.1179, -2.1179, -2.1179],
[-2.1179, -2.1179, -2.1179, ..., -2.1179, -2.1179, -2.1179],
[-2.1179, -2.1179, -2.1179, ..., -2.1179, -2.1179, -2.1179]],
[[-2.0357, -2.0357, -2.0357, ..., -2.0357, -2.0357, -2.0357],
[-2.0357, -2.0357, -2.0357, ..., -2.0357, -2.0357, -2.0357],
[-2.0357, -2.0357, -2.0357, ..., -2.0357, -2.0357, -2.0357],
...,
[-2.0357, -2.0357, -2.0357, ..., -2.0357, -2.0357, -2.0357],
[-2.0357, -2.0357, -2.0357, ..., -2.0357, -2.0357, -2.0357],
[-2.0357, -2.0357, -2.0357, ..., -2.0357, -2.0357, -2.0357]],
[[-1.8044, -1.8044, -1.8044, ..., -1.8044, -1.8044, -1.8044],
[-1.8044, -1.8044, -1.8044, ..., -1.8044, -1.8044, -1.8044],
[-1.8044, -1.8044, -1.8044, ..., -1.8044, -1.8044, -1.8044],
...,
[-1.8044, -1.8044, -1.8044, ..., -1.8044, -1.8044, -1.8044],
[-1.8044, -1.8044, -1.8044, ..., -1.8044, -1.8044, -1.8044],
[-1.8044, -1.8044, -1.8044, ..., -1.8044, -1.8044, -1.8044]]]])]},)
:Could not infer type of list element: Only tensors and (possibly nested) tuples of tensors, lists, or dictsare supported as inputs or outputs of traced functions, but instead got value of type DataContainer.
What did I found on the web
In MMDet repo issue someone has the same problem and tried to upgrade torch version. Which I did, I tried to put at 1.10 but it could not compile your repo because some codes became deprecated (I cannot compile torch 1.10, 1.11 with CUDA 11.1).
My environment is based on official torch docker images. From this image I just run the install instructions from the README.md expect the conda env and torch install.