This is a project for doing adversarial attack against Baidu Apollo's TL detection, selection and recognition pipeline. For data, please check https://zenodo.org/doi/10.5281/zenodo.8390340.
Check https://github.com/boyang9602/TLR-replicate/ if you only need to use Apollo TLR in Python & Pytorch.
- code/models/: the replicated models as well as the weights
- code/attack/: the adversarial attack related code files
- code/eval/: the evaluation code
- recognizer_eval: the code for test the robustness of/attack the recognizer standalone
- code/tools/: the utilites used in other modules.
You need to set the PYTHONPATH first.
- Open your terminal,
- Go to the root of the project
- Command
export PYTHONPATH=./code/
To set up the detection, selection and recognition pipeline
from models.pipeline import load_pipeline
torch.manual_seed(42) # for reproductibility, not necessary
device = "cuda" if torch.cuda.is_available() else "cpu"
pl = load(device=device)
valid_detections, recognitions, assignments, invalid_detections, rpn_data = pl(image, boxes) # image is the image file in bgr format, boxes is a list of single box, which is [xmin, ymin, xmax, ymax].
- valid_detections is a n * 9 tensor. The first column is useless in this project. 1:5 are the bounding boxes, 5:9 are the TL type scores vector.
- recognitions are the recognition scores vector.
- assignments is a n * 2 tensor. Each row is match between the projection and the valid detection. The first col is the idx of a projection of TLs and the second col is the idx of a valid detection.
- invalid_detections are discarded in Apollo and rpn_data is the intermediate data in RPN layer. They are used for the attack in this project.
Please follow this github repo to get the dataset. https://github.com/Thinklab-SJTU/S2TLD
tools/dataset.py is a simple dataset loader. It only supports the S2TLD dataset for now. It needs to generates a filelist.txt before using. Open your terminal and command
python tools/dataset.py <S2TLD 720 * 1280 path> <S2TLD 1080 * 1920 path>
To use the dataset,
from tools.dataset import get_dataset
device = "cuda" if torch.cuda.is_available() else "cpu"
ds = get_dataset(<'S2TLD720'|'S2TLD1080'>, device=device)
item = ds[idx]
'''
{
'image': ..., bgr format
'boxes': ...,
'colors': ...,
...
}
'''