I trained a model with the following configs as in the demo code;
def prepare_for_launch():
runner = GeneralizedRCNNRunner()
cfg = runner.get_default_cfg()
cfg.merge_from_file(model_zoo.get_config_file("faster_rcnn_fbnetv3g_fpn.yaml"))
cfg.MODEL_EMA.ENABLED = False
cfg.DATASETS.TRAIN = (tr,)
cfg.DATASETS.TEST = (ts,)
cfg.DATALOADER.NUM_WORKERS = 2
cfg.MODEL.WEIGHTS = "/home/exx/workspace/round1_fpn/model_0034999.pth"
cfg.SOLVER.IMS_PER_BATCH = 2
cfg.SOLVER.BASE_LR = 0.00025 # pick a good LR
cfg.SOLVER.MAX_ITER = 52045 # 35 iterations
cfg.SOLVER.STEPS = [324800, 365400] # do not decay learning rate
cfg.MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE = 512 # faster, and good enough for this toy dataset (def$
cfg.MODEL.ROI_HEADS.NUM_CLASSES = 6 # number of classes
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5
cfg.OUTPUT_DIR = "/home/exx/Desktop/yakkaya/d2go/workspace/round1_fpn"
os.makedirs(cfg.OUTPUT_DIR, exist_ok=True)
return cfg, runner
cfg, runner = prepare_for_launch()
And converted the trained model to int8 model.
model = runner.build_model(cfg)
# disable all the warnings
previous_level = logging.root.manager.disable
logging.disable(logging.INFO)
patch_d2_meta_arch()
#DetectionCheckpointer(model).load("/home/exx/workspace/round1_fpn/model_0034999.pth")
checkpointer = runner.build_checkpointer(cfg, model, save_dir=cfg.OUTPUT_DIR)
checkpoint = checkpointer.resume_or_load(cfg.MODEL.WEIGHTS, resume=True)
model.eval()
pytorch_model = model
pytorch_model.cpu()
datasets = cfg.DATASETS.TEST[0]
data_loader = runner.build_detection_test_loader(cfg, datasets)
predictor_path = convert_and_export_predictor(
cfg,
copy.deepcopy(pytorch_model),
"torchscript_int8",
'./new',
data_loader
)
# recover the logging level
logging.disable(previous_level)
The inference results with the converted model is not even close the original model. It has limited detections over %50 confidence score and they are irrelevant.
from mobile_cv.predictor.api import create_predictor
predictor_path = "/home/exx/workspace/new/torchscript_int8"
model = create_predictor(predictor_path)
from d2go.utils.demo_predictor import DemoPredictor
predictor = DemoPredictor(model)
meta = MetadataCatalog.get(ts)
dataset_dicts = DatasetCatalog.get(ts)
for i, d in enumerate(random.sample(dataset_dicts, 20)):
im = cv2.imread(d["file_name"])
outputs = predictor(im)
v = Visualizer(im[:, :, ::-1], metadata=meta, scale=0.8)
v = v.draw_instance_predictions(outputs["instances"].to("cpu"))
plt.figure(figsize = (14, 10))
plt.imshow(cv2.cvtColor(v.get_image()[:, :, ::-1], cv2.COLOR_BGR2RGB))
plt.savefig(f'/home/exx/workspace/inference/inf_{i}')
I trained a model with the following configs as in the demo code;
And converted the trained model to int8 model.
The inference results with the converted model is not even close the original model. It has limited detections over %50 confidence score and they are irrelevant.