Torchsummary on Pytorch detectron2 faster-rcnn

username: pradnesh
cooked: <pre><code class="lang-auto">import torch
import torchvision
from torchvision.models.detection import FasterRCNN
from torchvision.models.detection.rpn import AnchorGenerator
from torch.utils.data import Dataset, DataLoader
from PIL import Image
import copy
from torchsummary import summary

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

# Some basic setup:
# Setup detectron2 logger
import detectron2
from detectron2.utils.logger import setup_logger
setup_logger()

# import some common libraries
import numpy as np
import os, json, cv2, random

# import some common detectron2 utilities
from detectron2 import model_zoo
from detectron2.engine import DefaultPredictor
from detectron2.config import get_cfg
from detectron2.utils.visualizer import Visualizer
from detectron2.data import MetadataCatalog, DatasetCatalog

cfg = get_cfg()
cfg.keys()

cfg.merge_from_file(model_zoo.get_config_file("COCO-Detection/faster_rcnn_R_101_FPN_3x.yaml"))

cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5
# print(cfg.MODEL.ROI_HEADS)

predictor = DefaultPredictor(cfg)

# im = cv2.imread('./hico_20160224_det/images/train2015/HICO_train2015_00000001.jpg')
# plt.imshow(cv2.cvtColor(im, cv2.COLOR_BGR2RGB))
# plt.show()

# outputs = predictor(im)

# print(outputs["instances"].pred_classes)
# print(outputs["instances"].pred_boxes)

# v = Visualizer(im[:, :, ::-1], MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), scale=0.5)
# out = v.draw_instance_predictions(outputs["instances"].to("cpu"))
# plt.imshow(cv2.cvtColor(out.get_image()[:, :, ::-1], cv2.COLOR_BGR2RGB), cmap='gray')

print("Printing predictor.model ..................... \n\n")
print(predictor.model)

print("Printing model summary of predictor model ................ ")
model = copy.deepcopy(predictor.model)
model.eval()
print(summary(model, (3, 480, 640)))
</code></pre>
<p>Hello. I wish to get the model summary of the Faster-RCNN model from detectron2 to see how the input is getting manipulated by different layers. But the summary statement on the last line is failing in this case. I am attaching the traceback below for reference.</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/d/e/ded3a3c7cca9ce8934fbe7809166f5a096ab826e.png" data-download-href="https://discuss.pytorch.org/uploads/default/ded3a3c7cca9ce8934fbe7809166f5a096ab826e" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/d/e/ded3a3c7cca9ce8934fbe7809166f5a096ab826e_2_690x205.png" alt="image" data-base62-sha1="vNdqWpu5vmHEmUblFFn3BWSHc74" width="690" height="205" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/d/e/ded3a3c7cca9ce8934fbe7809166f5a096ab826e_2_690x205.png, https://discuss.pytorch.org/uploads/default/optimized/3X/d/e/ded3a3c7cca9ce8934fbe7809166f5a096ab826e_2_1035x307.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/d/e/ded3a3c7cca9ce8934fbe7809166f5a096ab826e_2_1380x410.png 2x" data-dominant-color="32363E"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1777×530 84.9 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>Any help is appreciated!</p>
<p>Thanks in advance.</p>
<p>Regards,<br>
Pradnesh<br>
IIT Guwahati</p>