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

Seeking Help with an Issue #2

Open
ZeoLuuuuuu opened this issue Feb 5, 2025 · 11 comments
Open

Seeking Help with an Issue #2

ZeoLuuuuuu opened this issue Feb 5, 2025 · 11 comments

Comments

@ZeoLuuuuuu
Copy link

The error message is as follows:

Traceback (most recent call last):
File "D:\Detection_code\VCO-AP-master\main.py", line 17, in
from attacking import attack
File "D:\Detection_code\VCO-AP-master\attacking.py", line 10, in
from mmdet.apis.test import normalize
ImportError: cannot import name 'normalize' from 'mmdet.apis.test' (D:\Anaconda3\envs\adv_defense\lib\site-packages\mmdet\apis\test.py)

I encountered an issue where the imported function could not be found while running your codes. The specific location is in line 10 of attacking.py: from mmdet.apis.test import normalize. My version of mmdet is 2.28.2, and only this imported function is missing. In your requirements.txt, the version of mmdet is specified as 3.2.0. However, after I changed to install version 3.2.0, I found that even more imported functions were missing. Could you please advise on how to resolve this issue? Thank you!

@ZeoLuuuuuu
Copy link
Author

I noticed that there is a custom normalize function in utils/misc.py. Can I use this one instead?

@ZeoLuuuuuu
Copy link
Author

I noticed that there is a custom normalize function in utils/misc.py. Can I use this one instead?

I tried to replace from mmdet.apis.test import normalize with from utils.misc import normalize. Although your code ran without errors, the generated perturbed images were completely black, and all the losses were nan. This doesn't work.So, what should I do to resolve this issue?

@WindVChen
Copy link
Owner

Hello @ZeoLuuuuuu ,

Could you try the following library version and check whether it works?

MMCV: 1.7.0, MMROTATE: 0.3.4, MMDET: 2.26.0

@ZeoLuuuuuu
Copy link
Author

Thank you very much for your reply. I have modified it according to your version, but unfortunately, it still does not work properly. It seems that the way the normalize() function is imported is incorrect. I could not find this function based on the import way you used in the official mmdet documentation with any versions.

Image
Image

@WindVChen
Copy link
Owner

Hello @ZeoLuuuuuu ,

You're absolutely right—the function is missing in the current code. Thanks for catching that!

I've just fixed the issue. You can either update the code to the latest version or check out the modifications here.

Hope this helps! Let me know if you run into any other issues.

@ZeoLuuuuuu
Copy link
Author

Hello @ZeoLuuuuuu ,

You're absolutely right—the function is missing in the current code. Thanks for catching that!

I've just fixed the issue. You can either update the code to the latest version or check out the modifications here.

Hope this helps! Let me know if you run into any other issues.

Thank you very much for the fix. Following your modifications, I have managed to resolve this issue on my end as well. I don’t have any further questions for now, but I will let you know if anything else comes up.

@ZeoLuuuuuu
Copy link
Author

ZeoLuuuuuu commented Feb 6, 2025

Hello, @WindVChen ,
I encountered a new issue. I just randomly selected four remote sensing images from DOTA 1.0 and tested to creat adversarial patches similar to those in your paper. The detector I used was ROI-Transformer, and I applied the pretrained harmonization weights you provided. However, after the optimization, the generated adversarial patches folder is empty, and all loss values are nan. Below are the command and the execution process:
python main.py --attack_image_root attacked_images --save_path_lut model/best.pth --lut_apply --is_eot --det_model_config det_configs/roi_trans_r50_fpn_1x_dota_le90.py --patch_size 20 --attack_pos corner --attack_epochs 10 --save_path ./logs

Namespace(train=False, resolution=512, image_path=None, save_path='./logs\exp5', seed=42, wandb=False, image_root='images', batch_size=8, dataloader_num_workers=12, iterations=1000, lr=1e-05, LUT_dim=7, lut_path='LUTs', save_visualization=True, save_path_lut='model/best.pth', attack_image_root='attacked_image', lut_apply=True, is_eot=True, det_model_config='det_configs/roi_trans_r50_fpn_1x_dota_le90.py', patch_size=40, attack_epochs=10, attack_pos='corner', tv_weight=100, nps_weight=0.0, det_model_checkpoint='pretrained/roi_trans_r50_fpn_1x_dota_le90-d1f0b77a.pth')
INFO:root:Namespace(train=False, resolution=512, image_path=None, save_path='./logs\exp5', seed=42, wandb=False, image_root='images', batch_size=8, dataloader_num_workers=12, iterations=1000, lr=1e-05, LUT_dim=7, lut_path='LUTs', save_visualization=True, save_path_lut='model/best.pth', attack_image_root='attacked_image', lut_apply=True, is_eot=True, det_model_config='det_configs/roi_trans_r50_fpn_1x_dota_le90.py', patch_size=40, attack_epochs=10, attack_pos='corner', tv_weight=100, nps_weight=0.0, det_model_checkpoint='pretrained/roi_trans_r50_fpn_1x_dota_le90-d1f0b77a.pth')
Start attacking detection model.
INFO:root:Start attacking detection model.
Splitting DOTA image...
INFO:root:Splitting DOTA image...
Loading original data!!!
Starting loading DOTA dataset information.
Finishing loading DOTA, get 4 iamges, using 0.013s.
Start splitting images!!!
2025-02-06 10:20:44,333 - (25.0% 1:4) - Filename: P0289.png - width: 1164 - height: 1196 - Objects: 0 - Patches: 16
2025-02-06 10:20:44,497 - (50.0% 2:4) - Filename: P0292.png - width: 1203 - height: 934 - Objects: 0 - Patches: 12
2025-02-06 10:20:44,757 - (75.0% 3:4) - Filename: P0294.png - width: 1424 - height: 1226 - Objects: 0 - Patches: 20
2025-02-06 10:20:44,862 - (100.0% 4:4) - Filename: P0301.png - width: 894 - height: 829 - Objects: 0 - Patches: 9
Finish splitting images in 1 second!!!
Total images number: 57
Finish DOTA image split.

INFO:root:Finish DOTA image split.

load checkpoint from local path: pretrained/roi_trans_r50_fpn_1x_dota_le90-d1f0b77a.pth
time: 20250206_102104 memory: 518 epoch: 0 loss: nan lossDet: nan lossTV: nan lossNPS: nan
INFO:root:time: 20250206_102104 memory: 518 epoch: 0 loss: nan lossDet: nan lossTV: nan lossNPS: nan
Save epoch 0 perturbations!
INFO:root:Save epoch 0 perturbations!
time: 20250206_102108 memory: 519 epoch: 1 loss: nan lossDet: nan lossTV: nan lossNPS: nan
INFO:root:time: 20250206_102108 memory: 519 epoch: 1 loss: nan lossDet: nan lossTV: nan lossNPS: nan
Save epoch 1 perturbations!
INFO:root:Save epoch 1 perturbations!
time: 20250206_102112 memory: 518 epoch: 2 loss: nan lossDet: nan lossTV: nan lossNPS: nan
INFO:root:time: 20250206_102112 memory: 518 epoch: 2 loss: nan lossDet: nan lossTV: nan lossNPS: nan
Save epoch 2 perturbations!
INFO:root:Save epoch 2 perturbations!
time: 20250206_102116 memory: 519 epoch: 3 loss: nan lossDet: nan lossTV: nan lossNPS: nan
INFO:root:time: 20250206_102116 memory: 519 epoch: 3 loss: nan lossDet: nan lossTV: nan lossNPS: nan
Save epoch 3 perturbations!
INFO:root:Save epoch 3 perturbations!
time: 20250206_102120 memory: 518 epoch: 4 loss: nan lossDet: nan lossTV: nan lossNPS: nan
INFO:root:time: 20250206_102120 memory: 518 epoch: 4 loss: nan lossDet: nan lossTV: nan lossNPS: nan
Save epoch 4 perturbations!
INFO:root:Save epoch 4 perturbations!
time: 20250206_102124 memory: 519 epoch: 5 loss: nan lossDet: nan lossTV: nan lossNPS: nan
INFO:root:time: 20250206_102124 memory: 519 epoch: 5 loss: nan lossDet: nan lossTV: nan lossNPS: nan
Save epoch 5 perturbations!
INFO:root:Save epoch 5 perturbations!
time: 20250206_102128 memory: 518 epoch: 6 loss: nan lossDet: nan lossTV: nan lossNPS: nan
INFO:root:time: 20250206_102128 memory: 518 epoch: 6 loss: nan lossDet: nan lossTV: nan lossNPS: nan
Save epoch 6 perturbations!
INFO:root:Save epoch 6 perturbations!
time: 20250206_102132 memory: 519 epoch: 7 loss: nan lossDet: nan lossTV: nan lossNPS: nan
INFO:root:time: 20250206_102132 memory: 519 epoch: 7 loss: nan lossDet: nan lossTV: nan lossNPS: nan
Save epoch 7 perturbations!
INFO:root:Save epoch 7 perturbations!
time: 20250206_102136 memory: 518 epoch: 8 loss: nan lossDet: nan lossTV: nan lossNPS: nan
INFO:root:time: 20250206_102136 memory: 518 epoch: 8 loss: nan lossDet: nan lossTV: nan lossNPS: nan
Save epoch 8 perturbations!
INFO:root:Save epoch 8 perturbations!
time: 20250206_102140 memory: 519 epoch: 9 loss: nan lossDet: nan lossTV: nan lossNPS: nan
INFO:root:time: 20250206_102140 memory: 519 epoch: 9 loss: nan lossDet: nan lossTV: nan lossNPS: nan
Save epoch 9 perturbations!
INFO:root:Save epoch 9 perturbations!
Start to save clean images (only those with targets)!

INFO:root:Start to save clean images (only those with targets)!

Start to save perturbations and perturbed images!

INFO:root:Start to save perturbations and perturbed images!

Start to save merged full perturbed image!

INFO:root:Start to save merged full perturbed image!

Start to save perturbations and perturbed images!

INFO:root:Start to save perturbations and perturbed images!

Start to save merged full perturbed image!

INFO:root:Start to save merged full perturbed image!

Evaluate the clean images ...

INFO:root:Evaluate the clean images ...

load checkpoint from local path: pretrained/roi_trans_r50_fpn_1x_dota_le90-d1f0b77a.pth
[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 57/57, 2.1 task/s, elapsed: 27s, ETA: 0sINFO:root:
+--------------------+-----+------+--------+-------+
| class | gts | dets | recall | ap |
+--------------------+-----+------+--------+-------+
| plane | 0 | 84 | 0.000 | 0.000 |
| baseball-diamond | 0 | 0 | 0.000 | 0.000 |
| bridge | 0 | 0 | 0.000 | 0.000 |
| ground-track-field | 0 | 0 | 0.000 | 0.000 |
| small-vehicle | 0 | 110 | 0.000 | 0.000 |
| large-vehicle | 0 | 163 | 0.000 | 0.000 |
| ship | 0 | 21 | 0.000 | 0.000 |
| tennis-court | 0 | 0 | 0.000 | 0.000 |
| basketball-court | 0 | 0 | 0.000 | 0.000 |
| storage-tank | 0 | 0 | 0.000 | 0.000 |
| soccer-ball-field | 0 | 0 | 0.000 | 0.000 |
| roundabout | 0 | 0 | 0.000 | 0.000 |
| harbor | 0 | 7 | 0.000 | 0.000 |
| swimming-pool | 0 | 0 | 0.000 | 0.000 |
| helicopter | 0 | 0 | 0.000 | 0.000 |
+--------------------+-----+------+--------+-------+
| mAP | | | | 0.000 |
+--------------------+-----+------+--------+-------+
{'mAP': 0.0}
INFO:root:{'mAP': 0.0}
Evaluate the perturbed images ...

INFO:root:Evaluate the perturbed images ...

It must be that I’m not familiar in running your program, and there should be some mistakes on my part. Could you please help me take a look on the information I provided and give me some modifications? I would be grateful if you could help me do that.

@WindVChen
Copy link
Owner

Hi,

I guess it may be because the sampled images do not include any valid objects.

I notice there are messages in your log as follows:

2025-02-06 10:20:44,333 - (25.0% 1:4) - Filename: P0289.png - width: 1164 - height: 1196 - Objects: 0 - Patches: 16
2025-02-06 10:20:44,497 - (50.0% 2:4) - Filename: P0292.png - width: 1203 - height: 934 - Objects: 0 - Patches: 12
2025-02-06 10:20:44,757 - (75.0% 3:4) - Filename: P0294.png - width: 1424 - height: 1226 - Objects: 0 - Patches: 20
2025-02-06 10:20:44,862 - (100.0% 4:4) - Filename: P0301.png - width: 894 - height: 829 - Objects: 0 - Patches: 9

@ZeoLuuuuuu
Copy link
Author

Hi,

I guess it may be because the sampled images do not include any valid objects.

I notice there are messages in your log as follows:

2025-02-06 10:20:44,333 - (25.0% 1:4) - Filename: P0289.png - width: 1164 - height: 1196 - Objects: 0 - Patches: 16
2025-02-06 10:20:44,497 - (50.0% 2:4) - Filename: P0292.png - width: 1203 - height: 934 - Objects: 0 - Patches: 12
2025-02-06 10:20:44,757 - (75.0% 3:4) - Filename: P0294.png - width: 1424 - height: 1226 - Objects: 0 - Patches: 20
2025-02-06 10:20:44,862 - (100.0% 4:4) - Filename: P0301.png - width: 894 - height: 829 - Objects: 0 - Patches: 9

Hi,
I attempted today to place over 100 remote sensing images from the DOTA 1.0 training set into the attack_image_root directory. However, the output for each image was Objects: 0. I also tried changing the det_model_config and its corresponding pre-trained model, but the printed information remained essentially the same as yesterday.
Could you please advise on what other issues might have occurred?

@WindVChen
Copy link
Owner

That is a bit weird. Could you check whether there is any object in the label file? Or if the label file is under the same file structure as follows?

├── root
    ├── images
        ├── <name_1>.png
    ├── labelTxt
        ├── <name_1>.txt (DOTA-Format)

Since from the information in your logs, it seems there are objects detected by the networks, but there are no groundtruth objects:

| class | gts | dets | recall | ap |
+--------------------+-----+------+--------+-------+
| plane | 0 | 84 | 0.000 | 0.000 |
| baseball-diamond | 0 | 0 | 0.000 | 0.000 |
| bridge | 0 | 0 | 0.000 | 0.000 |
| ground-track-field | 0 | 0 | 0.000 | 0.000 |
| small-vehicle | 0 | 110 | 0.000 | 0.000 |
| large-vehicle | 0 | 163 | 0.000 | 0.000 |
| ship | 0 | 21 | 0.000 | 0.000 |
| tennis-court | 0 | 0 | 0.000 | 0.000 |
| basketball-court | 0 | 0 | 0.000 | 0.000 |
| storage-tank | 0 | 0 | 0.000 | 0.000 |
| soccer-ball-field | 0 | 0 | 0.000 | 0.000 |
| roundabout | 0 | 0 | 0.000 | 0.000 |
| harbor | 0 | 7 | 0.000 | 0.000 |
| swimming-pool | 0 | 0 | 0.000 | 0.000 |
| helicopter | 0 | 0 | 0.000 | 0.000 |

@ZeoLuuuuuu
Copy link
Author

Thank you so much. I finally managed to do it. I didn't place the label file according to the file structure you provided, which was a minor mistake.

Start attacking detection model.
INFO:root:Start attacking detection model.
Splitting DOTA image...
INFO:root:Splitting DOTA image...
Loading original data!!!
Starting loading DOTA dataset information.
Finishing loading DOTA, get 2 iamges, using 0.012s.
Start splitting images!!!
2025-02-10 11:48:26,838 - (50.0% 1:2) - Filename: P0327.png - width: 1749 - height: 1921 - Objects: 128 - Patches: 42
2025-02-10 11:48:34,254 - (100.0% 2:2) - Filename: P1161.png - width: 6266 - height: 6627 - Objects: 25 - Patches: 600
Finish splitting images in 8 second!!!
Total images number: 642
Finish DOTA image split.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants