facebookarchive / adversarial_image_defenses

Countering Adversarial Image using Input Transformations.
Other
487 stars 75 forks source link

ImportError("tv_bregman not found. Check build script") #2

Closed ysharma1126 closed 6 years ago

ysharma1126 commented 6 years ago

All dependencies have been installed, including Faiss, as per instructions, however when running the demo script, the following error is triggered. What is meant by 'check build script'?

mayankrana commented 6 years ago

@ysharma1126 , I am unable to reproduce this error, could you check the following?

  1. The build script setup.py(called by pip install .) should generate file tv_bregman.so. If it failed to generate the .so file then ideally you should get an error during pip install .. You can verify if .so file is created at adversarial/lib/transformations/tv_bregman.so (PS: The adversarial directory in the path should be the directory where adversarial package is installed and not the source directory in adversarial_image_defenses).
  2. In python, when you do import adversarial.lib.transformations.tvm. With the above error you should also get the path from where tvm.py is being loaded. Check if the path is the same where "adversarial" package is installed and not the path for the source directory(where you git cloned).
  3. You can also post the full error here if it still doesn't work. Also, which python version are you using?
ysharma1126 commented 6 years ago

1) When I run 'pip install .', I'm alerted that all requirements are satisfied and adversarial-0.1.0 was installed successfully. However, in the transformations directory, tv_bregman.so is not found. If I run python setup.py build_ext, I now have tv_bregman.c and tv_bregman.pyx in the transformations directory, but still not tv_bregman.so. I didn't get any errors.

2) I get the following error: Traceback (most recent call last): File "", line 1, in File "adversarial/lib/transformations/tvm.py", line 16, in raise ImportError("tv_bregman not found. Check build script") ImportError: tv_bregman not found. Check build script

3) Full error posted above. I'm using Python 2.7

mayankrana commented 6 years ago

When you do python setup.py build_ext, It will generate the .so and other build files in the build directory inside adversarial_image_defenses. Its just that they are not copied with the src code files. python setup.py build_ext --inplace can help with that. That will be able to fix the above error but then you may need to edit the demo.py to import local adversarial. Instead of build_ext, I will recommend the pip install ., as you won't need to change any code then.

I think whats happening is your pip install . is successful but you are trying to do import adversarial or import adversarial.lib.transformations.tvm from the directory adversarial_image_defenses. As this directory has a sub directory with the name adversarial, So when you do import from there it gives preference to the the local directory over the installed package with the same name. I would recommend, after successful pip install ., go to the parent directory of adversarial_image_defenses and then in python do import adversarial. After import adversarial, print(adversarial.file) can tell you if your installed package is being loaded or the directory adversarial_image_defenses/adversarial. If you are able to successfully import adversarial, then you should also be able to import adversarial.lib.transformations.tvm without the above error. I will update the setup.py to print the path of the installed package to remove above confusion. Let me know if you are able to make it work.

ysharma1126 commented 6 years ago

Yep, you were correct! The library works if I execute commands from the parent directory of adversarial_image_dfenses! Thanks again!

ysharma1126 commented 6 years ago

Now I get the following error when running demo.py:

| Defense: quilting | load quilting patch data... Traceback (most recent call last): File "adversarial_image_defenses/adversarial/examples/demo.py", line 107, in _generate_transformed_images() File "adversarial_image_defenses/adversarial/examples/demo.py", line 67, in _generate_transformed_images generate_transformed_images(args) File "/home/yash/yash_env/local/lib/python2.7/site-packages/adversarial/gen_transformed_images.py", line 220, in generate_transformed_images defense = get_defense(defense_name, args) File "/home/yash/yash_env/local/lib/python2.7/site-packages/adversarial/lib/defenses.py", line 82, in get_defense with open(patches_filename, 'rb') as fread: IOError: [Errno 2] No such file or directory: '/tmp/adverarial_dataset/patches_5.pickle'

mayankrana commented 6 years ago

Yes, because you don't have patch dataset for quilting. See generate quilting patches section in readme for more details on how to generate patches for image quilting, for more details on quilting you can reference this paper. Once the patches are generated, you can update it's path in path_config.json. You may also want to update path for imagenet_dir and data_root in the config file so that index_patches code can find the image dataset for generating patches. Also, if you just want to run the demo and don't want to generate quilting patches, in demo.py, replace "quilting" in args.defenses with "tvm" which will run TVM defense instead of quilting defense.

ysharma1126 commented 6 years ago

Understood. Thanks Mayank!