<jupyter_start><jupyter_text>Training RetinaNet<jupyter_code>%load_ext autoreload
%autoreload 2
from importlib.util import find_spec
if find_spec("model") is None:
    import sys
    sys.path.append('..')
from fastai.vision.all import *
import torch.nn as nn
from data_loader.data_loaders import load_sample_coco_dls
from model.backbone.fpn import FPN, retinanet_fpn_resnet
from model.model import retina_resnet50
from model.loss import RetinaLoss<jupyter_output><empty_output><jupyter_text>Load the Data<jupyter_code>dls = load_sample_coco_dls(bs=16)
dls.show_batch()<jupyter_output><empty_output><jupyter_text>Build the Model<jupyter_code>fpn_module = FPN(upsample_stages=[2048, 256], downsample_stages=[2048, 1024, 512])
fpn_module
retina_fpn = retinanet_fpn_resnet()
retina_fpn<jupyter_output><empty_output><jupyter_text>RetinaNet50<jupyter_code>num_classes = 6
model = retina_resnet50(num_classes=num_classes)<jupyter_output><empty_output><jupyter_text>Focal Loss  Allow Low Quality Matches<jupyter_code>criterion = RetinaLoss(num_classes=num_classes, allow_low_quality_matches=True)<jupyter_output><empty_output><jupyter_text>Freeze everything except encoder (base arch).<jupyter_code>def _retinanet_split(m): return L(m.base, nn.Sequential(m.backbone, m.head)).map(params)
learn = Learner(dls, model, loss_func=criterion, splitter=_retinanet_split)
learn.freeze()
learn.fit_one_cycle(10, slice(1e-5, 1e-4))<jupyter_output><empty_output><jupyter_text>Don't Allow Low Quality Matches<jupyter_code>criterion = RetinaLoss(num_classes=num_classes)
learn = Learner(dls, model, loss_func=criterion, splitter=_retinanet_split)
learn.freeze()
learn.fit_one_cycle(10, slice(1e-5, 1e-4))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10624635143023935, 'fraction_numerical': 0.023350846468184472, 'mean_word_length': 10.820689655172414, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '270026', 'license': 'MIT', 'n_tokens_mistral': 694, 'n_tokens_neox': 659, 'n_words': 98, 'path': 'notebooks/20_training_retinanet.ipynb', 'repo_name': 'mhd53/retinanet-from-torch', 'size': '1713'}