<jupyter_start><jupyter_text>In this notebook I tried experimenting with Nvidia Retinanet model<jupyter_code>%load_ext autoreload
%autoreload 2
import os
os.chdir("./retinanet_nvidia/retinanet-examples/")
from retinanet.model import Model
import torch, torchvision
from utils.dataset import *
from utils.evaluator import *
from utils.trainer import MTSDTrainer

# from detectron2.data import DatasetCatalog
# from detectron2.utils.logger import setup_logger

# import some common libraries
import numpy as np
import os, json, cv2, random
import matplotlib.pyplot as plt

# 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
# from detectron2.engine import DefaultTrainer
from datetime import datetime


# from detectron2_backbone import backbone
# from detectron2_backbone.config import add_backbone_config

#import the COCO Evaluator to use the COCO Metrics
# from detectron2.evaluation import COCOEvaluator, inference_on_dataset
# from detectron2.data import build_detection_test_loader<jupyter_output><empty_output><jupyter_text>converting MTSD annotations to json<jupyter_code>ann_d="/mnt/CommonData/dataset/filtered_annotations_2/"
img_d="/home/pkos/Desktop/mtsd_fully_annotated/images/"
l_id_f="/home/pkos/workspace/inz/praca_inzynierska/lbl_id_dict.pkl"
id_f_train="/home/pkos/Desktop/mtsd_fully_annotated/splits/train.txt"
id_f_val = "/home/pkos/Desktop/mtsd_fully_annotated/splits/val.txt"
with open('dataset_dicts.pkl', 'rb') as f:
    dataset_dicts = pickle.load(f)
with open(l_id_f, 'rb') as f:
        lbl_id_map = pickle.load(f)
labels = list(lbl_id_map.keys())
img_d = "/data/images/"
dict_coco_train = convert_MTSD_to_COCO(id_f_train, ann_d, img_d, l_id_f)
dict_coco_val = convert_MTSD_to_COCO(id_f_val, ann_d, img_d, l_id_f)
output_json = "/home/pkos/workspace/inz/praca_inzynierska/mtsd_coco_dict_train.json"
write_json(dict_coco_train, output_json)
output_json = "/home/pkos/workspace/inz/praca_inzynierska/mtsd_coco_dict_val.json"
write_json(dict_coco_val, output_json)<jupyter_output><empty_output><jupyter_text>separating train and val<jupyter_code>img_d_train="/home/pkos/Desktop/mtsd_fully_annotated/images_train/"
img_d_val = "/home/pkos/Desktop/mtsd_fully_annotated/images_val/"
train = read_list_from_file('/mnt/CommonData/dataset/mtsd_fully_annotated/splits/train.txt')
val = read_list_from_file('/mnt/CommonData/dataset/mtsd_fully_annotated/splits/val.txt')
import os
from shutil import copyfile
for file_id in train:
    src = img_d + file_id + ".jpg"
    dst = img_d_train + file_id +".jpg"
    copyfile(src, dst)
    
for file_id in val:
    src = img_d + file_id + ".jpg"
    dst = img_d_val + file_id +".jpg"
    copyfile(src, dst)<jupyter_output><empty_output><jupyter_text>inference<jupyter_code>model = torch.load("/home/pkos/workspace/inz/praca_inzynierska/retinanet_nvidia/trained_models/model_20k.pth")
model.keys()
from torchvision.models.resnet import resnet34
model = resnet34(pretrained=True).eval().cuda()
model.load_state_dict(torch.load("/home/pkos/workspace/inz/praca_inzynierska/retinanet_nvidia/trained_models/model_20k.pth")['or'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09913147648996705, 'fraction_numerical': 0.0071877807726864335, 'mean_word_length': 6.713625866050808, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '20630', 'license': 'MIT', 'n_tokens_mistral': 1258, 'n_tokens_neox': 1235, 'n_words': 215, 'path': 'detection_model/nvidia_retinanet_test.ipynb', 'repo_name': 'ptrkstrk/roadeye_jetson', 'size': '3339'}