{"id":17719882,"url":"https://github.com/yizhe-ang/detectron2-1","last_synced_at":"2025-05-12T20:42:30.812Z","repository":{"id":38786592,"uuid":"272368784","full_name":"yizhe-ang/detectron2-1","owner":"yizhe-ang","description":"Implements Adversarial Examples for Semantic Segmentation and Object Detection, using PyTorch and Detectron2","archived":false,"fork":false,"pushed_at":"2021-02-27T12:03:11.000Z","size":7761,"stargazers_count":29,"open_issues_count":2,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-03-06T10:07:54.640Z","etag":null,"topics":["adversarial-attacks","adversarial-examples","adversarial-machine-learning","detectron","detectron2","object-detection","pytorch","segmentation"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yizhe-ang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-15T07:18:47.000Z","updated_at":"2023-03-02T14:32:30.000Z","dependencies_parsed_at":"2022-09-03T19:01:45.931Z","dependency_job_id":null,"html_url":"https://github.com/yizhe-ang/detectron2-1","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yizhe-ang%2Fdetectron2-1","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yizhe-ang%2Fdetectron2-1/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yizhe-ang%2Fdetectron2-1/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yizhe-ang%2Fdetectron2-1/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yizhe-ang","download_url":"https://codeload.github.com/yizhe-ang/detectron2-1/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253818009,"owners_count":21969087,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["adversarial-attacks","adversarial-examples","adversarial-machine-learning","detectron","detectron2","object-detection","pytorch","segmentation"],"created_at":"2024-10-25T15:11:18.960Z","updated_at":"2025-05-12T20:42:30.769Z","avatar_url":"https://github.com/yizhe-ang.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Detectron2.1\nThis repository contains experiments on the generation of Adversarial Examples for Object Detection tasks, in particular for logo and input box detection for phishing website detection applications.\n\nThe primary technique used is the Dense Adversary Generation (DAG) algorithm from [Adversarial Examples for Semantic Segmentation and Object Detection (Xie et al., ICCV 2017)](https://arxiv.org/abs/1703.08603), and is implemented on the [Detectron2](https://github.com/facebookresearch/detectron2) framework.\n\nReport on Adversarial Examples for Object Detection: [REPORT.md](REPORT.md)\n\n# Installation\n```\ngit clone https://github.com/lemonwaffle/detectron2-1.git\n```\nTo install Detectron2 and its dependencies, refer to the official [installation instructions](https://github.com/facebookresearch/detectron2/blob/master/INSTALL.md).\n\n# Directory\nMake sure the data files are organized as follows:\n```\n├── GETTING_STARTED.md\n├── LICENSE\n├── README.md\n├── configs  # Contains config files that control training parameters\n├── data\n│   └── benign_data\n│       ├── benign_database  # Contains all the images\n│       ├── coco_test.json  # Test annotations in COCO format\n│       └── coco_train.json  # Train annotations in COCO format\n├── detectron2_1\n│   ├── __init__.py\n│   └── datasets.py  # Registers train and test datasets\n├── requirements.txt\n└── train_net.py  # Main entry point for model training\n```\n\n# Config\nEach training run is completely defined by customizable parameters in its configuration file, with a few templates already specified in the [configs](./configs) folder.\n\nFor example, all the existing config files train the models with pretrained COCO weights:\n- `cascade_mask_rcnn.yaml`: Cascade Mask R-CNN model with ResNet50 backbone.\n- `faster_rcnn.yaml`: Faster R-CNN model with ResNet50 backbone.\n- `retinanet.yaml`: RetinaNet model with ResNet50 backbone.\n\nOther types of models and their respective configs and pretrained weights can be found in the official Detectron2 [Model Zoo](https://github.com/facebookresearch/detectron2/blob/master/MODEL_ZOO.md).\n\nWhile you can refer to the [config reference](https://detectron2.readthedocs.io/modules/config.html#config-references) for a full list of available parameters and what they mean, I've annotated some of them in the existing configs, and some notable ones to customize are:\n- `SOLVER.IMS_PER_BATCH`: Batch size\n- `SOLVER.BASE_LR`: Base learning rate\n- `SOLVER.STEPS`: The iteration number to decrease learning rate by GAMMA\n- `SOLVER.MAX_ITER`: Total number of training iterations\n- `SOLVER.CHECKPOINT_PERIOD`: Saves checkpoint every number of steps\n- `INPUT.MIN_SIZE_TRAIN`: Image input sizes\n- `TEST.EVAL_PERIOD`: The period (in terms of steps) to evaluate the model during training\n- `OUTPUT_DIR`: Specify output directory to save checkpoints, logs, results etc.\n\n# Training\nTo train on a single gpu:\n```\npython train_net.py \\\n    --config-file configs/retinanet.yaml\n```\n\nTo train on multiple gpus:\n```\npython train_net.py \\\n    --num-gpus 4 \\\n    --config-file configs/retinanet.yaml\n```\n\nTo resume training from a checkpoint (finds last checkpoint from cfg.OUTPUT_DIR)\n```\npython train_net.py \\\n    --config-file config.yaml \\  # Config file of halted run\n    --resume\n```\n\nTo see all options:\n```\npython train_net.py -h\n```\n\n# Visualization\n## Training Examples\nTo visualize annotations of raw training images:\n```\npython visualize_data.py \\\n    --config-file config.yaml \\  # Uses dataset specified in cfg.DATASETS.TRAIN\n    --source annotation \\\n    --num-imgs 1000 \\  # Num of images to save; don't specify if want to save all\n    --output-dir /dir/to/save/images\n```\n\nTo visualize annotations of training images after preprocessing/augs:\n```\npython visualize_data.py \\\n    --config-file config.yaml \\  # Uses dataset specified in cfg.DATASETS.TRAIN\n    --source dataloader \\\n    --num-imgs 1000 \\  # Num of images to save; don't specify if want to save all\n    --output-dir /dir/to/save/images\n```\n\n## Predictions\nTo visualize JSON predictions:\n```\npython visualize_json_results.py \\\n    --input coco_instances_results.json \\  # JSON file produced by model\n    --output /dir/to/save/images \\\n    --dataset benign_test \\  # Name of dataset\n    --conf-threshold 0.5  # Default 0.5\n```\n\n## Training Curves\nLosses and metrics are automatically logged to TensorBoard.\n```\ntensorboard --logdir {path}\n```\n\n# Evaluation\nThis command only runs evaluation on the test dataset:\n```\npython train_net.py \\\n    --eval-only \\\n    --config-file configs/retinanet.yaml \\\n    MODEL.WEIGHTS /path/to/checkpoint_file  # Path to trained checkpoint\n```\n\n# Run DAG Algorithm\n```\npython run_DAG.py \\\n    --cfg-path config.yaml \\\n    --weights-path model_final.pth \\\n    --results-save-path coco_instances_results.json \\\n    --vis-save-dir saved\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyizhe-ang%2Fdetectron2-1","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyizhe-ang%2Fdetectron2-1","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyizhe-ang%2Fdetectron2-1/lists"}