Skip to content

Commit dff2bde

Browse files
authored
Merge pull request #1715 from Trusted-AI/development_issue_1640
Add Estimator for YOLO object detection models in PyTorch
2 parents f73029b + 89a0d5b commit dff2bde

File tree

10 files changed

+1035
-2
lines changed

10 files changed

+1035
-2
lines changed

.github/actions/yolo/Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Get base from a pytorch image
2+
FROM pytorch/pytorch:1.11.0-cuda11.3-cudnn8-runtime
3+
4+
# Set to install things in non-interactive mode
5+
ENV DEBIAN_FRONTEND noninteractive
6+
7+
# Install system wide software
8+
RUN apt-get update \
9+
&& apt-get install -y \
10+
libgl1-mesa-glx \
11+
libx11-xcb1 \
12+
git \
13+
gcc \
14+
mono-mcs \
15+
cmake \
16+
libavcodec-extra \
17+
ffmpeg \
18+
curl \
19+
wget \
20+
&& apt-get clean all \
21+
&& rm -r /var/lib/apt/lists/*
22+
23+
RUN pip install six setuptools tqdm
24+
RUN pip install numpy==1.21.6 scipy==1.8.1 scikit-learn==1.1.1 numba==0.55.1
25+
RUN pip install torch==1.11.0
26+
RUN pip install tensorflow==2.9.1
27+
RUN pip install pytest-cov
28+
29+
# Install necessary libraries for Yolo v3
30+
RUN pip install pytorchyolo==1.6.2
31+
32+
RUN cd /tmp/ && git clone https://github.com/eriklindernoren/PyTorch-YOLOv3.git
33+
RUN cd PyTorch-YOLOv3/weights && ./download_weights.sh

.github/actions/yolo/action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: 'Test YOLO'
2+
description: 'Run tests for YOLO'
3+
runs:
4+
using: 'composite'
5+
steps:
6+
- run: $GITHUB_ACTION_PATH/run.sh
7+
shell: bash

.github/actions/yolo/run.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
exit_code=0
4+
5+
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/estimators/object_detection/test_pytorch_yolo.py --framework=pytorch --durations=0
6+
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed estimators/speech_recognition/test_pytorch_yolo tests"; fi
7+
8+
exit ${exit_code}

.github/workflows/ci-yolo.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: CI PyTorchYolo
2+
on:
3+
# Run on manual trigger
4+
workflow_dispatch:
5+
6+
# Run on pull requests
7+
pull_request:
8+
paths-ignore:
9+
- '*.md'
10+
11+
# Run when pushing to main or dev branches
12+
push:
13+
branches:
14+
- main
15+
- dev*
16+
17+
# Run scheduled CI flow daily
18+
schedule:
19+
- cron: '0 8 * * 0'
20+
21+
jobs:
22+
test_deepspeech_v3_torch_1_10:
23+
name: PyTorchYolo
24+
runs-on: ubuntu-latest
25+
container: adversarialrobustnesstoolbox/art_testing_envs:yolo
26+
steps:
27+
- name: Checkout Repo
28+
uses: actions/checkout@v3
29+
- name: Run Test Action
30+
uses: ./.github/actions/yolo
31+
- name: Upload coverage to Codecov
32+
uses: codecov/codecov-action@v3
33+
with:
34+
fail_ci_if_error: true

art/estimators/object_detection/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55

66
from art.estimators.object_detection.pytorch_object_detector import PyTorchObjectDetector
77
from art.estimators.object_detection.pytorch_faster_rcnn import PyTorchFasterRCNN
8+
from art.estimators.object_detection.pytorch_yolo import PyTorchYolo
89
from art.estimators.object_detection.tensorflow_faster_rcnn import TensorFlowFasterRCNN

art/estimators/object_detection/pytorch_faster_rcnn.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737

3838
class PyTorchFasterRCNN(PyTorchObjectDetector):
3939
"""
40-
This class implements a model-specific object detector using Faster-RCNN and PyTorch.
40+
This class implements a model-specific object detector using Faster-RCNN and PyTorch following the input and output
41+
formats of torchvision.
4142
"""
4243

4344
def __init__(

art/estimators/object_detection/pytorch_object_detector.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939

4040
class PyTorchObjectDetector(ObjectDetectorMixin, PyTorchEstimator):
4141
"""
42-
This module implements the task specific estimator for PyTorch object detectors.
42+
This module implements the task specific estimator for PyTorch object detection models following the input and
43+
output formats of torchvision.
4344
"""
4445

4546
estimator_params = PyTorchEstimator.estimator_params + ["attack_losses"]

0 commit comments

Comments
 (0)