Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integretion of YoloV5 as possible pose estimation model #4

Open
wants to merge 45 commits into
base: main_refactor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
fe16019
yet another test with pytorch's transformation functions
phanfeld Jun 13, 2024
7a21d08
correct implementation of perspecitve grid for our purposes
phanfeld Jun 13, 2024
7eac91a
adapted old scripts to work with new and correct perspective transfor…
phanfeld Jun 13, 2024
3fc6e02
tests with different patch sizes, transformation matrices apparently …
phanfeld Jun 13, 2024
313593f
perspective_grid function: copy transformation matrix coefficients di…
phanfeld Jun 17, 2024
394d45e
adapted perspective grid function to work with batches
phanfeld Jun 17, 2024
524dde9
got rid of additional tampering with the transformation coefficients …
phanfeld Jun 17, 2024
332eaa5
minimal example of one optimization step to debug position optimizati…
phanfeld Jun 17, 2024
bf3c417
optimizing position working only if interpolation mode of grid sample…
phanfeld Jun 17, 2024
73b6f59
adapted example settings.yaml to include configurable patch size, ada…
phanfeld Jun 27, 2024
5e8522c
testing to work with torch.multiprocessing to train patches I
phanfeld Jun 27, 2024
30ffda7
spawn multiple attack.py jobs on cluster, create 1 patch for up to 3 …
phanfeld Jul 2, 2024
c55bd48
changed number of random targets to max 3
phanfeld Jul 2, 2024
2c3f89e
added function to pickle all optimized patches
phanfeld Jul 3, 2024
72dc77f
fixed bug with tx/ty range in normalization function
phanfeld Jul 5, 2024
cd2a312
merge complete
phanfeld Jul 9, 2024
2c19fa7
calculating test loss on whole test set in one batch to accelerate da…
phanfeld Jul 11, 2024
abd20a3
code version for fine tuning the diffusion patches
phanfeld Aug 7, 2024
423ea55
added calculation of anytime loss
phanfeld Aug 7, 2024
b94c776
calculate patches for heatmap plot
phanfeld Aug 7, 2024
4aa9d12
scripts + changes to calculate heatmap data and anytime loss
phanfeld Aug 9, 2024
c67c94d
anytime loss and heatmap plot for gt patches
phanfeld Aug 9, 2024
64ee315
version of scripts for heatmap and anytime loss
phanfeld Aug 22, 2024
8f9d856
change to generate many patches in parallel
natalieh235 Jul 5, 2024
4a35611
changes
natalieh235 Jul 5, 2024
9e8a9fa
patches
natalieh235 Jul 9, 2024
540217c
start yolo
natalieh235 Jul 11, 2024
d9bb577
testing
natalieh235 Jul 12, 2024
b7211e8
camera testing
natalieh235 Jul 17, 2024
e3d0e3b
yolo testing
natalieh235 Jul 17, 2024
b3f0160
model to test
natalieh235 Jul 31, 2024
53e755e
remove yolo
natalieh235 Jul 31, 2024
87ff3a8
fix
natalieh235 Jul 31, 2024
84d2eda
changes
natalieh235 Aug 1, 2024
5460658
ignore logs
natalieh235 Aug 19, 2024
5650ced
generate and test yolo patches
natalieh235 Aug 19, 2024
db66032
diffusion model
natalieh235 Aug 26, 2024
7a11439
documentation
natalieh235 Aug 26, 2024
cc348f7
Update NATALIE_README.md
natalieh235 Aug 27, 2024
a4e67ed
tests and adaptations for dataset creation on hemera
phanfeld Sep 20, 2024
be1a908
non-breaking integration of yolo model for position estimation
phanfeld Sep 20, 2024
e284d7d
deleted yaml files
phanfeld Sep 24, 2024
8db2ebb
deleted unnecessary files / changed settings back to main branch sett…
phanfeld Sep 24, 2024
f336f78
updated gitignore
phanfeld Sep 24, 2024
4779fff
additional clean up
phanfeld Sep 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,15 @@ dmypy.json

# Pyre type checker
.pyre/

*.out
results/
minimal_patches/
parallel_compute/
*.pickle
*.pkl
*.sh
*.sbatch
*.pth
test/
src/custom_patches/diffusion_patches_100.npy
52 changes: 52 additions & 0 deletions NATALIE_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
## YOLO Adversarial Patches
All changes are here: https://github.com/natalieh235/flying_adversarial_patch/tree/yolo

### src/attacks.py
`python3 attacks.py --file settings.yaml --task task_num`
- added task_num param (int) for generating many patches in parallel
- changed targeted_attack_joint to use the YOLOBounding class to predict the person coordinates instead
- currently, only targets that are valid in the image pixel context are generated

### src/run_attacks.py
- generates many patches in parallel using multiprocessing module
- change `start_task_id`, `end_task_id`, and `num_runs`
- change `OUTPUT_PATH` to save log files (stderr and stdout)

### src/test_yolo_patches.py
`python3 src/test_yolo_patches.py --start start_patch_id --end end_patch_id`
- functions for calculating error of yolo patches and displaying them (params are starting and ending patch_id)
- expects that patches are saved in PATH folder in the same format `attacks.py` saves them in (npy files), and each patch has a corresponding `settings_patchid.yaml` file
<br><br/>
For each patch:
1. loads the patch from `PATH/last_patch_id.npy`
2. loads the optimized position from `PATH/position_norm_id.npy`
3. loads the targets from `PATH/settings.yaml`
4. for each target, generates an image from the dataset with the patch placed at the optimized position for that target
5. for each patch, calculates the MSE between the center of the highest confidence bounding box and the actual target for a random image in the dataset for all targets
6. for each patch/target pair, saves an image in `RESULT_PATH/yolo_boxes_{patch_id}_target_{target_id}.png` that displays the patch placed on the image, the target, and the predicted YOLO bounding boxes (red is highest confidence, then blue, green, purple) <br> See example in `test_yolo_example.png`

The error printed isn't the error over the entire dataset for all patches, just the average loss for all patches when placed on ONE randomly selected image from the Frontnet dataset.

### src/yolo_bounding.py
has class `YOLOBox`, a wrapper around the YOLO ultralytics model that skips the normal NMS step and takes a weighted average to calculate the highest confidence bounding box so that the output is differentiable
- uses the ultralytics YOLOv5 nano module with `autoshape=False` so that it can take batched inputs
- the score assigned to each box is the product of the objectness score and the person_class score, calculated in `extract_boxes_and_scores`
- model(input) outputs bounding box coordinates of the highest confidence box for each image
- used in `attacks.py` to train patches against the YOLO model

### src/camera.py
- wrapper class around camera functions, takes a cam config file as param
Functions:
- `xyz_from_bb` calculates xyz coords from a bounding box
- `tensor_xyz_from_bb` same thing, but with tensors
- `point_from_xyz` calculates image point from xyz coords

### src/create_dataset.py
- creates a pkl file that stores patch data
- call `save_pickle(start_patch_id, end_patch_id)` to create a pkl file for patches from start_id to end_id inclusive
- saves only the best target for each patch

### Other
All the patches I generated (653, but only 578 with valid targets) are saved in `all_yolo_patches.pkl`
Diffusion model trained for 1000 epochs, 1000 denoising steps (approx 23 min training) is saved in `yolo_conditioned_unet_80x80_1000_3256i_255.pth ` (uploaded to the TUB drive) <br>
Samples from that model are saved in `samples_conditioning_4_80x80.png`
1 change: 1 addition & 0 deletions camera/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("hi")
8 changes: 8 additions & 0 deletions dataset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
#SBATCH -c 4
#SBATCH --gres=gpu:1
#SBATCH -p gpu
#SBATCH --time=00:30:00

source /home/hanfeld/.front-env/bin/activate
python src/attacks.py --file $1
30 changes: 30 additions & 0 deletions dataset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
path: 'results/dataset'
# +x is distance
# +y is left
# +z is top
targets:
x : [ 1.0, 1.5, 0.5, 2.0, 1.0, 1.0]
y : [ 0.0, 0.0, 0.0, 0.0, 1.0, -1.0]
z : [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
stlc: # small-time locally controllability
offsets:
# base
- target: [0,0,0]
position: [0,0,0]
lr_pos: 0.001
lr_patch: 0.01
prob_weight: 1.0
num_hl_iter: 50
num_pos_restarts: 3
num_pos_epochs: 1
num_patch_epochs: 1
batch_size: 32
num_patches: 1
scale_min: 0.2
scale_max: 0.7
patch:
mode: 'random' # face, white, random
size: [80, 80] # patch size in [height, width]
path: 'src/custom_patches/custom_patch_96x160.npy' # if mode == 'face' set a path, otherwise path is ignored
mode: "joint" # fixed, joint, split, hybrid
quantized: false
Loading