Trusted-AI/adversarial-robustness-toolbox

Troubleshooting and Solution for 'unsupported operand type(s) for /' Error in adversarial_patch_tensorflow.py (Line 277)

deepakupman opened this issue · 2 comments

Encountered the following error in the provided code snippet link. I resolved it by incorporating the provided code adjustment.

Error message:

File "C:\ProgramData\anaconda3\lib\site-packages\art\attacks\evasion\adversarial_patch\adversarial_patch_tensorflow.py", line 277, in _random_overlay
pad_h_before = int((self.image_shape[self.i_h] - image_mask.shape[self.i_h_patch + 1]) / 2)
File "C:\ProgramData\anaconda3\lib\site-packages\tensorflow\python\framework\tensor_shape.py", line 559, in truediv
raise TypeError("unsupported operand type(s) for /: 'Dimension' and '{}', "
TypeError: unsupported operand type(s) for /: 'Dimension' and 'int', please use // instead

Code fix:
pad_h_before = int((self.image_shape[self.i_h] - image_mask.shape.as_list()[self.i_h_patch + 1]) / 2)

I have implemented additional code modifications to address the same issue at line 280, 326 & 329

Please review the following changes and consider incorporating them into your repository.

Hi @deepakupman Thank you very much for noticing and reporting this issue! Would you be interested in opening a pull request for you solution?

Yeah Sure, I will do it.