WaqasSultani / AnomalyDetectionCVPR2018

502 stars 182 forks source link

TypeError: index must be integers(TrainingAnomalyDetector_public.py) #55

Open seulgi111 opened 5 years ago

seulgi111 commented 5 years ago

hi I want to run the TrainingAnomalyDetector_public.py, but i met problems.


/home/seul/anaconda3/envs/anomaly0/bin/python /home/seul/Downloads/AnomalyDetectionCVPR2018-master/TrainingAnomalyDetector_public.py Using cuDNN version 7005 on context None Mapped name None to device cuda0: GeForce GTX 1080 Ti (0000:01:00.0) Using Theano backend. Create Model Traceback (most recent call last): File "/home/seul/Downloads/AnomalyDetectionCVPR2018-master/TrainingAnomalyDetector_public.py", line 279, in model.compile(loss=custom_objective, optimizer=adagrad) File "/home/seul/anaconda3/envs/anomaly0/lib/python3.6/site-packages/keras/models.py", line 547, in compile kwargs) File "/home/seul/anaconda3/envs/anomaly0/lib/python3.6/site-packages/keras/engine/training.py", line 622, in compile sample_weight, mask) File "/home/seul/anaconda3/envs/anomaly0/lib/python3.6/site-packages/keras/engine/training.py", line 324, in weighted score_array = fn(y_true, y_pred) File "/home/seul/Downloads/AnomalyDetectionCVPR2018-master/TrainingAnomalyDetector_public.py", line 253, in custom_objective sub_sum_l1 = sub_sum_l1[:n_exp] File "/home/seul/anaconda3/envs/anomaly0/lib/python3.6/site-packages/theano/tensor/var.py", line 572, in getitem return theano.tensor.subtensor.advanced_subtensor(self, args) File "/home/seul/anaconda3/envs/anomaly0/lib/python3.6/site-packages/theano/gof/op.py", line 615, in call node = self.make_node(inputs, kwargs) File "/home/seul/anaconda3/envs/anomaly0/lib/python3.6/site-packages/theano/tensor/subtensor.py", line 2227, in make_node return super(AdvancedSubtensor, self).make_node(x, index) File "/home/seul/anaconda3/envs/anomaly0/lib/python3.6/site-packages/theano/tensor/subtensor.py", line 2178, in make_node index = tuple(map(as_index_variable, index)) File "/home/seul/anaconda3/envs/anomaly0/lib/python3.6/site-packages/theano/tensor/subtensor.py", line 2072, in as_index_variable return make_slice(idx) File "/home/seul/anaconda3/envs/anomaly0/lib/python3.6/site-packages/theano/gof/op.py", line 615, in call node = self.make_node(inputs, kwargs) File "/home/seul/anaconda3/envs/anomaly0/lib/python3.6/site-packages/theano/tensor/type_other.py", line 39, in make_node list(map(as_int_none_variable, inp)), File "/home/seul/anaconda3/envs/anomaly0/lib/python3.6/site-packages/theano/tensor/type_other.py", line 20, in as_int_none_variable raise TypeError('index must be integers') TypeError: index must be integers**


Can you help me solve this problem? Thank you for reading.

LiUzHiAn commented 5 years ago

Hi, @seulgi111 I think this error was raised by the variable n_exp. In python 3, the result type of a/b is defaulted set to float. Maybe you can modify the line 93 into n_exp=batchsize//2 instead.

awesome-yz commented 4 years ago

Has anyone resolved this problem as yet?

hi I want to run the TrainingAnomalyDetector_public.py, but i met problems.

/home/seul/anaconda3/envs/anomaly0/bin/python /home/seul/Downloads/AnomalyDetectionCVPR2018-master/TrainingAnomalyDetector_public.py Using cuDNN version 7005 on context None Mapped name None to device cuda0: GeForce GTX 1080 Ti (0000:01:00.0) Using Theano backend. Create Model Traceback (most recent call last): File "/home/seul/Downloads/AnomalyDetectionCVPR2018-master/TrainingAnomalyDetector_public.py", line 279, in model.compile(loss=custom_objective, optimizer=adagrad) File "/home/seul/anaconda3/envs/anomaly0/lib/python3.6/site-packages/keras/models.py", line 547, in compile kwargs) File "/home/seul/anaconda3/envs/anomaly0/lib/python3.6/site-packages/keras/engine/training.py", line 622, in compile sample_weight, mask) File "/home/seul/anaconda3/envs/anomaly0/lib/python3.6/site-packages/keras/engine/training.py", line 324, in weighted score_array = fn(y_true, y_pred) File "/home/seul/Downloads/AnomalyDetectionCVPR2018-master/TrainingAnomalyDetector_public.py", line 253, in custom_objective sub_sum_l1 = sub_sum_l1[:n_exp] File "/home/seul/anaconda3/envs/anomaly0/lib/python3.6/site-packages/theano/tensor/var.py", line 572, in getitem return theano.tensor.subtensor.advanced_subtensor(self, args) File "/home/seul/anaconda3/envs/anomaly0/lib/python3.6/site-packages/theano/gof/op.py", line 615, in call node = self.make_node(inputs, kwargs) File "/home/seul/anaconda3/envs/anomaly0/lib/python3.6/site-packages/theano/tensor/subtensor.py", line 2227, in make_node return super(AdvancedSubtensor, self).make_node(x, index) File "/home/seul/anaconda3/envs/anomaly0/lib/python3.6/site-packages/theano/tensor/subtensor.py", line 2178, in make_node index = tuple(map(as_index_variable, index)) File "/home/seul/anaconda3/envs/anomaly0/lib/python3.6/site-packages/theano/tensor/subtensor.py", line 2072, in as_index_variable return make_slice(idx) File "/home/seul/anaconda3/envs/anomaly0/lib/python3.6/site-packages/theano/gof/op.py", line 615, in call node = self.make_node(inputs, kwargs) File "/home/seul/anaconda3/envs/anomaly0/lib/python3.6/site-packages/theano/tensor/type_other.py", line 39, in make_node list(map(as_int_none_variable, inp)), File "/home/seul/anaconda3/envs/anomaly0/lib/python3.6/site-packages/theano/tensor/type_other.py", line 20, in as_int_none_variable raise TypeError('index must be integers') TypeError: index must be integers**

Can you help me solve this problem? Thank you for reading.

PHDPeter commented 4 years ago

I had a similar thing and I found that "n_exp = nvid / 2" also needed to be changed to "n_exp = nvid // 2" on line 206 of TrainingAnomalyDetector_public.py. After doing that it worked for me. Hope that helps.

Villjoie commented 4 years ago

I have the same problem, did someone solve it ?

Using TensorFlow backend. WARNING:tensorflow:From /home/socialab/PycharmProjects/Master/V_master/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:17: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.

Create Model WARNING:tensorflow:From /home/socialab/PycharmProjects/Master/V_master/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:293: calling RandomNormal.init (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version. Instructions for updating: Call initializer instance with the dtype argument instead of passing it to the constructor WARNING:tensorflow:From /home/socialab/PycharmProjects/Master/V_master/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:152: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.

WARNING:tensorflow:From /home/socialab/PycharmProjects/Master/V_master/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:72: The name tf.get_default_session is deprecated. Please use tf.compat.v1.get_default_session instead.

WARNING:tensorflow:From /home/socialab/PycharmProjects/Master/V_master/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:76: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

WARNING:tensorflow:From /home/socialab/PycharmProjects/Master/V_master/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:76: The name tf.ConfigProto is deprecated. Please use tf.compat.v1.ConfigProto instead.

2020-01-26 18:48:24.480613: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 3601895000 Hz 2020-01-26 18:48:24.481023: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x4bac610 initialized for platform Host (this does not guarantee that XLA will be used). Devices: 2020-01-26 18:48:24.481043: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version 2020-01-26 18:48:24.483435: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1 2020-01-26 18:48:24.627458: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2020-01-26 18:48:24.628155: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x49077b0 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices: 2020-01-26 18:48:24.628175: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): GeForce GTX 1080, Compute Capability 6.1 2020-01-26 18:48:24.628333: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2020-01-26 18:48:24.628791: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1639] Found device 0 with properties: name: GeForce GTX 1080 major: 6 minor: 1 memoryClockRate(GHz): 1.898 pciBusID: 0000:01:00.0 2020-01-26 18:48:24.628925: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcudart.so.10.0'; dlerror: libcudart.so.10.0: cannot open shared object file: No such file or directory 2020-01-26 18:48:24.628993: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcublas.so.10.0'; dlerror: libcublas.so.10.0: cannot open shared object file: No such file or directory 2020-01-26 18:48:24.629058: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcufft.so.10.0'; dlerror: libcufft.so.10.0: cannot open shared object file: No such file or directory 2020-01-26 18:48:24.629123: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcurand.so.10.0'; dlerror: libcurand.so.10.0: cannot open shared object file: No such file or directory 2020-01-26 18:48:24.629187: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcusolver.so.10.0'; dlerror: libcusolver.so.10.0: cannot open shared object file: No such file or directory 2020-01-26 18:48:24.629252: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcusparse.so.10.0'; dlerror: libcusparse.so.10.0: cannot open shared object file: No such file or directory 2020-01-26 18:48:24.632837: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7 2020-01-26 18:48:24.632860: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1662] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform. Skipping registering GPU devices... 2020-01-26 18:48:24.632881: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1180] Device interconnect StreamExecutor with strength 1 edge matrix: 2020-01-26 18:48:24.632891: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1186] 0 2020-01-26 18:48:24.632899: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1199] 0: N WARNING:tensorflow:From /home/socialab/PycharmProjects/Master/V_master/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:242: calling Constant.init (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version. Instructions for updating: Call initializer instance with the dtype argument instead of passing it to the constructor WARNING:tensorflow:From /home/socialab/PycharmProjects/Master/V_master/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:1463: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version. Instructions for updating: Please use rate instead of keep_prob. Rate should be set to rate = 1 - keep_prob. WARNING:tensorflow:Large dropout rate: 0.6 (>0.5). In TensorFlow 2.x, dropout() uses dropout rate instead of keep_prob. Please ensure that this is intended. WARNING:tensorflow:Large dropout rate: 0.6 (>0.5). In TensorFlow 2.x, dropout() uses dropout rate instead of keep_prob. Please ensure that this is intended. Traceback (most recent call last): File "/home/socialab/PycharmProjects/Master/V_master/anotar_imagens/AnomalyDetectionCVPR2018-master/TrainingAnomalyDetector_public.py", line 276, in model.compile(loss=custom_objective, optimizer=adagrad) File "/home/socialab/PycharmProjects/Master/V_master/venv/lib/python3.6/site-packages/keras/models.py", line 547, in compile **kwargs) File "/home/socialab/PycharmProjects/Master/V_master/venv/lib/python3.6/site-packages/keras/engine/training.py", line 622, in compile sample_weight, mask) File "/home/socialab/PycharmProjects/Master/V_master/venv/lib/python3.6/site-packages/keras/engine/training.py", line 324, in weighted score_array = fn(y_true, y_pred) File "/home/socialab/PycharmProjects/Master/V_master/anotar_imagens/AnomalyDetectionCVPR2018-master/TrainingAnomalyDetector_public.py", line 199, in custom_objective y_true = T.flatten(y_true) File "/home/socialab/PycharmProjects/Master/V_master/venv/lib/python3.6/site-packages/theano/tensor/basic.py", line 5276, in flatten x_reshaped = x.reshape(dims) AttributeError: 'Tensor' object has no attribute 'reshape' TrainingAnomalyDetector_public.txt

PHDPeter commented 4 years ago

@Villjoie this does not look like the same issues I had but have you try the fix above?

arash9900 commented 4 years ago

I have the same problem, did someone solve it ?

Using TensorFlow backend. WARNING:tensorflow:From /home/socialab/PycharmProjects/Master/V_master/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:17: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.

Create Model WARNING:tensorflow:From /home/socialab/PycharmProjects/Master/V_master/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:293: calling RandomNormal.init (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version. Instructions for updating: Call initializer instance with the dtype argument instead of passing it to the constructor WARNING:tensorflow:From /home/socialab/PycharmProjects/Master/V_master/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:152: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.

WARNING:tensorflow:From /home/socialab/PycharmProjects/Master/V_master/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:72: The name tf.get_default_session is deprecated. Please use tf.compat.v1.get_default_session instead.

WARNING:tensorflow:From /home/socialab/PycharmProjects/Master/V_master/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:76: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

WARNING:tensorflow:From /home/socialab/PycharmProjects/Master/V_master/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:76: The name tf.ConfigProto is deprecated. Please use tf.compat.v1.ConfigProto instead.

2020-01-26 18:48:24.480613: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 3601895000 Hz 2020-01-26 18:48:24.481023: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x4bac610 initialized for platform Host (this does not guarantee that XLA will be used). Devices: 2020-01-26 18:48:24.481043: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version 2020-01-26 18:48:24.483435: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1 2020-01-26 18:48:24.627458: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2020-01-26 18:48:24.628155: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x49077b0 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices: 2020-01-26 18:48:24.628175: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): GeForce GTX 1080, Compute Capability 6.1 2020-01-26 18:48:24.628333: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2020-01-26 18:48:24.628791: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1639] Found device 0 with properties: name: GeForce GTX 1080 major: 6 minor: 1 memoryClockRate(GHz): 1.898 pciBusID: 0000:01:00.0 2020-01-26 18:48:24.628925: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcudart.so.10.0'; dlerror: libcudart.so.10.0: cannot open shared object file: No such file or directory 2020-01-26 18:48:24.628993: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcublas.so.10.0'; dlerror: libcublas.so.10.0: cannot open shared object file: No such file or directory 2020-01-26 18:48:24.629058: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcufft.so.10.0'; dlerror: libcufft.so.10.0: cannot open shared object file: No such file or directory 2020-01-26 18:48:24.629123: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcurand.so.10.0'; dlerror: libcurand.so.10.0: cannot open shared object file: No such file or directory 2020-01-26 18:48:24.629187: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcusolver.so.10.0'; dlerror: libcusolver.so.10.0: cannot open shared object file: No such file or directory 2020-01-26 18:48:24.629252: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcusparse.so.10.0'; dlerror: libcusparse.so.10.0: cannot open shared object file: No such file or directory 2020-01-26 18:48:24.632837: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7 2020-01-26 18:48:24.632860: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1662] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform. Skipping registering GPU devices... 2020-01-26 18:48:24.632881: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1180] Device interconnect StreamExecutor with strength 1 edge matrix: 2020-01-26 18:48:24.632891: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1186] 0 2020-01-26 18:48:24.632899: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1199] 0: N WARNING:tensorflow:From /home/socialab/PycharmProjects/Master/V_master/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:242: calling Constant.init (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version. Instructions for updating: Call initializer instance with the dtype argument instead of passing it to the constructor WARNING:tensorflow:From /home/socialab/PycharmProjects/Master/V_master/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:1463: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version. Instructions for updating: Please use rate instead of keep_prob. Rate should be set to rate = 1 - keep_prob. WARNING:tensorflow:Large dropout rate: 0.6 (>0.5). In TensorFlow 2.x, dropout() uses dropout rate instead of keep_prob. Please ensure that this is intended. WARNING:tensorflow:Large dropout rate: 0.6 (>0.5). In TensorFlow 2.x, dropout() uses dropout rate instead of keep_prob. Please ensure that this is intended. Traceback (most recent call last): File "/home/socialab/PycharmProjects/Master/V_master/anotar_imagens/AnomalyDetectionCVPR2018-master/TrainingAnomalyDetector_public.py", line 276, in model.compile(loss=custom_objective, optimizer=adagrad) File "/home/socialab/PycharmProjects/Master/V_master/venv/lib/python3.6/site-packages/keras/models.py", line 547, in compile **kwargs) File "/home/socialab/PycharmProjects/Master/V_master/venv/lib/python3.6/site-packages/keras/engine/training.py", line 622, in compile sample_weight, mask) File "/home/socialab/PycharmProjects/Master/V_master/venv/lib/python3.6/site-packages/keras/engine/training.py", line 324, in weighted score_array = fn(y_true, y_pred) File "/home/socialab/PycharmProjects/Master/V_master/anotar_imagens/AnomalyDetectionCVPR2018-master/TrainingAnomalyDetector_public.py", line 199, in custom_objective y_true = T.flatten(y_true) File "/home/socialab/PycharmProjects/Master/V_master/venv/lib/python3.6/site-packages/theano/tensor/basic.py", line 5276, in flatten x_reshaped = x.reshape(dims) AttributeError: 'Tensor' object has no attribute 'reshape' TrainingAnomalyDetector_public.txt

you should use theano backend

Villjoie commented 4 years ago

Hi, @PHDPeter

Yes, but this was more due to theano-backend

I solved it by putting described here: https://keras.io/backend/

@ataafarin thank you

sakshijain032 commented 4 years ago

There are two places where you need to change n_exp=batchsize//2 on line 125 n_exp = nvid // 2 on line 238

yassinesamet commented 3 years ago

@Villjoie please can you help me I have the same problem can you send me the new code pleaaaase ?