cuteboyqq / skip-GANOMALY-Pytorch

GANomaly, Skip-Ganomaly, Skip-CBAM-GANomaly, pytorch, CIFAR10, MNIST
7 stars 0 forks source link

Question about test.py #1

Open deamonyi opened 1 year ago

deamonyi commented 1 year ago

I am a beginner in GAN. After training with the skip-attention-ganomaly model in my own data set, the following problems occurred in my testing. $python test.py --normal-dir D:/DEMO/DATA/IDS/train --abnormal-dir D:/DEMO/DATA/IDS/test --view-img --img-size 32

D:\Anaconda\envs\skipganomaly\lib\site-packages\torchvision\io\image.py:13: UserWarning: Failed to load image Python extension:
  warn(f"Failed to load image Python extension: {e}")
img_test_data length : 126
test_loader length : 126
img_test_data length : 506
test_loader length : 506
Start test :

Loading pre-trained networks.
        Done.

load model weight from D:/DEMO/GANomaly/skip-GANOMALY-Pytorch/runs/train/2023 success
VAL_DATA_DIR : D:/DEMO/DATA/IDS/train
0 Start normal AE:
loss : 40.313087463378906
1 Start normal AE:
loss : 42.76571273803711

...

124 Start normal AE:
loss : 41.13412094116211
125 Start normal AE:
loss : 38.43585968017578
Traceback (most recent call last):
  File "test.py", line 210, in <module>
    main()
  File "test.py", line 45, in main
    test(args)
  File "test.py", line 82, in test
    'normal',device,args)
  File "test.py", line 144, in infer
    images, labels = dataiter.next()
  File "D:\Anaconda\envs\skipganomaly\lib\site-packages\torch\utils\data\dataloader.py", line 681, in __next__
    data = self._next_data()
  File "D:\Anaconda\envs\skipganomaly\lib\site-packages\torch\utils\data\dataloader.py", line 720, in _next_data
    index = self._next_index()  # may raise StopIteration
  File "D:\Anaconda\envs\skipganomaly\lib\site-packages\torch\utils\data\dataloader.py", line 671, in _next_index
    return next(self._sampler_iter)  # may raise StopIteration
StopIteration

I don't know if this is normal, and I don't know how I can tell if the test set is abnormal.

wsj-create commented 1 year ago

normal_loss = infer(test_loader,len(test_loader),skip_attention_ganomaly,criterion,normal_loss, 'normal',device,args) SHOW_MAX_NUM-->len(test_loader)

deamonyi commented 1 year ago

normal_loss = infer(test_loader,len(test_loader),skip_attention_ganomaly,criterion,normal_loss, 'normal',device,args) SHOW_MAX_NUM-->len(test_loader)

Thank you for helping me solve this problem.

deamonyi commented 1 year ago

I also found that the directory for custom data was a bit of a problem. After testing, the directories available are as follows BD8WH4 8X$5}57$5I0P@K@0

cuteboyqq commented 1 year ago

thank for correction !

I also found that the directory for custom data was a bit of a problem. After testing, the directories available are as follows BD8WH4 8X$5}57$5I0P@K@0

wsj-create commented 1 year ago

I also found that the directory for custom data was a bit of a problem. After testing, the directories available are as follows BD8WH4 8X$5}57$5I0P@K@0

The train directory has no errors and I can use

deamonyi commented 1 year ago

I also found that the directory for custom data was a bit of a problem. After testing, the directories available are as follows BD8WH4 8X$5}57$5I0P@K@0

The train directory has no errors and I can use You're right, but when you run test.py, using the original test directory will prompt you with no classes.

wsj-create commented 1 year ago

You're right

You're right

wsj-create commented 1 year ago

image Should self.batchsize be test_batchsize in this place?

wsj-create commented 1 year ago

@deamonyi @cuteboyqq

cuteboyqq commented 1 year ago

l trace to load_data.py , it seems both train batchsize and test batchsize using the same args.batch_size.

wsj-create commented 1 year ago

l trace to load_data.py , it seems both train batchsize and test batchsize using the same args.batch_size.

Yes, you used the same args.batch_size, should it be args.test_batchsize when test.

cuteboyqq commented 1 year ago

I think both is OK, maybe I was too lazy to use different batch size when l write the code. You can try to modify the code and use different batch size.

phonver commented 1 year ago

normal_loss = infer(test_loader,len(test_loader),skip_attention_ganomaly,criterion,normal_loss,normal_loss = inerate(test_loader,len(test_loader),skip_attention_ganomaly,criterion,normal_loss, 'normal',device,args) SHOW_MAX_NUM-->len(test_loader)'normal',device,args)SHOW_MAX_NUM--〉len(test_loader)

Can you explain it please? What does this loss represent? Also, why do I need to input both normal and abnormal samples during testing? How can I determine whether the image I input is normal or abnormal? thankyou

cuteboyqq commented 1 year ago

Answer: normal_loss = infer(test_loader,len(test_loader),skip_attention_ganomaly,criterion,normal_loss,normal_loss = inerate(test_loader,len(test_loader),skip_attention_ganomaly,criterion,normal_loss, 'normal',device,args) SHOW_MAX_NUM-->len(test_loader)'normal',device,args)SHOW_MAX_NUM--〉len(test_loader) ~ ~ Can you explain it please? What does this loss represent? Also, why do I need to input both normal and abnormal samples during testing? How can I determine whether the image I input is normal or abnormal? thankyou

Q1 : Can you explain it please? A1: it means inference the normal dataset

Q2:What does this loss represent? A2: normal dataset loss value is lower than anomaly dataset relatively. For example : if normal dataset are male images , you only train male images , the GANomaly model only recognize the male images, so when you inference male images, the loss value should be low. But if you infernece female image, the GANomaly model do not see this type of images before, so the loss value of female images is much higher than male images That is , for example male image 1 loss : 0.51 male image 2 loss : 0.78 male image 3 loss : 0.42 ... female image 1 loss : 1.23 female image 2 loss : 2.56 female image 3 loss : 4.52 ... So you can give a loss threshold to determine the final image is male or female(anomaly)

Q3: Also, why do I need to input both normal and abnormal samples during testing? A3: you can regard the non-normal images as anomaly(abnormal) samples , because you need to see if the model ables to distinguish the normal and abnormal by loss value.