<jupyter_start><jupyter_text>DEtection TRansformer Network ---  1. Import Modules<jupyter_code>%load_ext autoreload
%autoreload 2

from detr_models.detr.model import DETR
from detr_models.detr.train import get_image_information

from detr_models.detr.data_feeder import DataFeeder
from detr_models.detr.uuid_iterator import UUIDIterator
from detr_models.detr.config import DefaultDETRConfig
from detr_models.backbone.backbone import Backbone

import tensorflow as tf

import os<jupyter_output><empty_output><jupyter_text>---  2. Initialize Model<jupyter_code># Specify storage path
storage_path = input(prompt='Please specify the storage path:\n')
# Additional Information used for initialization
config = DefaultDETRConfig()

input_shape, count_images = get_image_information(storage_path)

backbone_config = {
        "input_shape": input_shape,
        "include_top": False,
        "weights": "imagenet",
    }

# Init. model
detr = DETR(
        storage_path=storage_path,
        input_shape=input_shape,
        num_queries=config.num_queries,
        num_classes=config.num_classes,
        num_heads=config.num_heads,
        dim_transformer=config.dim_transformer,
        dim_feedforward=config.dim_feedforward,
        num_transformer_layer=config.num_transformer_layer,
        backbone_name=config.backbone_name,
        backbone_config=backbone_config,
        train_backbone=False,
)<jupyter_output><empty_output><jupyter_text>---  3. Build Model<jupyter_code># Build Model
model = detr.build_model()

model.summary()<jupyter_output><empty_output><jupyter_text>---  4. Train Model<jupyter_code># Specify use_pretrained if you want to use pretrained weights
use_pretrained = input(prompt='Please specify the path to the pre-trained weights:\n')
# Init Optimizer
optimizer = tf.keras.optimizers.Adam(config.learning_rate)

# Start Training
detr.train(
        epochs=config.epochs,
        optimizer=optimizer,
        batch_size=config.batch_size,
        count_images=count_images,
        use_pretrained=use_pretrained,
        output_dir=args.output_dir,
    )<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08396584440227704, 'fraction_numerical': 0.0023719165085388993, 'mean_word_length': 4.669354838709677, 'pattern_counts': {'":': 3, '<': 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': '43686', 'license': 'MIT', 'n_tokens_mistral': 687, 'n_tokens_neox': 675, 'n_words': 127, 'path': 'notebooks/DETR.ipynb', 'repo_name': 'LucasKirsten/detr-tensorflow', 'size': '2108'}