LeeDoYup / AnoGAN-tf

Unofficial Tensorflow Implementation of AnoGAN (Anomaly GAN)
MIT License
270 stars 92 forks source link

Testing trained anomaly detector: Error: None values not supported #38

Open burgetrm opened 4 years ago

burgetrm commented 4 years ago

To repeat the issue: 1) Download data: python download.py mnist 2) Train a model
python main.py --dataset mnist --input_height=28 --output_height=28 --train 3) Prepare test data Downloaded sample images and put them to test_data folder 4) Run anomaly detection python main.py --dataset mnist --batch_size=64 --input_height=28 --output_height=28 --crop --anomaly_test

Error:

  File "main.py", line 129, in <module>
    tf.app.run()
  File "/home/.conda/envs/AnoGan/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 40, in run
    _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
  File "/home/.conda/envs/AnoGan/lib/python2.7/site-packages/absl/app.py", line 300, in run
    _run_main(main, args)
  File "/home/.conda/envs/AnoGan/lib/python2.7/site-packages/absl/app.py", line 251, in _run_main
    sys.exit(main(argv))
  File "main.py", line 117, in main
    dcgan.anomaly_detector()
  File "/home/NoveltyDetection/AnoGan/model.py", line 487, in anomaly_detector
    self.ano_G = self._sampler(self.ano_z, self.ano_y, batch_size=1)
  File "/home/NoveltyDetection/AnoGan/model.py", line 431, in _sampler
    yb = tf.reshape(y, [self.batch_size, 1, 1, self.y_dim])
  File "/home/.conda/envs/AnoGan/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 7715, in reshape
    "Reshape", tensor=tensor, shape=shape, name=name)
  File "/home/.conda/envs/AnoGan/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 545, in _apply_op_helper
    (input_name, err))
ValueError: Tried to convert 'tensor' to a tensor and failed. Error: None values not supported.

Cause: https://github.com/LeeDoYup/AnoGAN/blob/4c650b3ab606a810c63cbb1f8289debbe25bb405/model.py#L478

https://github.com/LeeDoYup/AnoGAN/blob/4c650b3ab606a810c63cbb1f8289debbe25bb405/model.py#L428

Environment: Python 2.7 Tensorflow 1.14.0

Experiment no. 1 trying to solve the issue: self.ano_y = tf.placeholder(tf.float32, [self.test_batch_size, self.y_dim], name='y') Output: ValueError: Cannot reshape a tensor with 10 elements to shape [64,1,1,10] (640 elements) for 'generator_2/Reshape' (op: 'Reshape') with input shapes: [1,10], [4] and with input tensors computed as partial shapes: input[1] = [64,1,1,10].

similar results also with [1, 1, 1, self.y_dim] or [1, 1, self.y_dim]

burgetrm commented 4 years ago

It seems using celebA instead of MNIST works well: 1) Download data: python download.py celebA 2) Train a model python main.py --dataset celebA --input_height=28 --output_height=28 --train --batch_size=1024 3) Prepare test data used the original data (test_01.png, test_02.png) 4) Run anomaly detection python main.py --dataset celebA --input_height=28 --output_height=28 --batch_size=1024 --anomaly_test

Anyway, if anyone has a solution for MNIST, would be grateful.

SurPer-Y commented 4 years ago

It seems using celebA instead of MNIST works well: 1) Download data: python download.py celebA 2) Train a model python main.py --dataset celebA --input_height=28 --output_height=28 --train --batch_size=1024 3) Prepare test data used the original data (test_01.png, test_02.png) 4) Run anomaly detection python main.py --dataset celebA --input_height=28 --output_height=28 --batch_size=1024 --anomaly_test

Anyway, if anyone has a solution for MNIST, would be grateful.

Could you please tell me what are in the test_data when I anomaly test mnist? i meet the same trouble and i think maybe the trouble is the test pics.

TheWangYang commented 1 year ago

I also ran into this problem: I got the same error above when testing on the mnist dataset. Looking forward to your answers.