facebookarchive / adversarial_image_defenses

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

Segfault encountered when running demo.py #6

Closed ssnl closed 6 years ago

ssnl commented 6 years ago

faiss with openblas on Ubuntu 16. From gdb it seems to segfault on a dynamic cast.

gdb outputs:

==============================GENERATING QUILTING PATCHES AND INDICES==============================
| Input args are:
Namespace(batchsize=256, data_params={'IMAGE_SIZE': 224, 'IMAGE_SCALE_SIZE': 256}, data_root='/tmp/adverarial_dataset', defenses=None, device='gpu', imagenet_dir='/home/ssnl/anaconda3/lib/python3.6/site-packages/adversarial/lib/../test/images', index_file='/tmp/tmp.faiss', model='resnet50', models_root='/tmp/adverarial_dataset', normalize=False, num_patches=1000000, patches_file='/tmp/tmp.pickle', pca_dims=64, pixel_drop_rate=0.5, preprocessed_data=False, pretrained=False, quantize_depth=8, quilting_index_root='/tmp/adverarial_dataset', quilting_neighbors=1, quilting_patch_root='/tmp/adverarial_dataset', quilting_patch_size=5, quilting_random_stitch=False, tar_dir='/tmp/adverarial_dataset/imagenet_transformed_tarred', tar_index_dir='/tmp/adverarial_dataset/imagenet_transformed_tarred_index', tar_prefix='tmp/imagenet_transformed', tvm_method='bregman', tvm_weight=0.03)
| set up image loader...
/home/ssnl/anaconda3/lib/python3.6/site-packages/torchvision/transforms/transforms.py:397: UserWarning: The use of the transforms.RandomSizedCrop transform is deprecated, please use transforms.RandomResizedCrop instead.
  "please use transforms.RandomResizedCrop instead.")
| Loading data from /home/ssnl/anaconda3/lib/python3.6/site-packages/adversarial/lib/../test/images/train
| gather image patches...
| training faiss index...#############################################################################################################################################################################################################################################################################################|
| writing faiss index to /tmp/adverarial_dataset/index_5.faiss

Thread 1 "python" received signal SIGSEGV, Segmentation fault.
__cxxabiv1::__dynamic_cast (src_ptr=src_ptr@entry=0x555601f4fb90, src_type=0x7fff8f336b90 <typeinfo for faiss::VectorTransform>, dst_type=dst_type@entry=0x7fff8f336ba0 <typeinfo for faiss::LinearTransform>, src2dst=src2dst@entry=0)
    at /opt/conda/conda-bld/compilers_linux-64_1505664199673/work/.build/src/gcc-7.2.0/libstdc++-v3/libsupc++/dyncast.cc:68
68  /opt/conda/conda-bld/compilers_linux-64_1505664199673/work/.build/src/gcc-7.2.0/libstdc++-v3/libsupc++/dyncast.cc: No such file or directory.

cc @taesung89

lvdmaaten commented 6 years ago

I am wondering if the /tmp/adverarial_dataset folder actually gets created somewhere? Does the error go away when you run mkdir /tmp/adverarial_dataset right before running the demo?

ssnl commented 6 years ago

The folder does seem to exist after running the script. I also tried deleting it, mkdir a new one, and then run the script. But it still segfaults. So far this has been reproduced on two Ubuntu 16 machines.

taesungp commented 6 years ago

I think I found the reason.

In index_patches.py, quantizer and pca_matrix are instantiated and used to create faiss_index inside a local function. But then they get freed by Swig library when they go out of scope. These instances are later referenced inside write_index and cause segfault.

To make the code work, simply returning references of quantizer and pca_matrix at the end of index_patches to prevent garbage collection is sufficient, but I think more fundamentally something should be fixed on Swig or faiss side. I attached the backtrace of deallocation.

image

mayankrana commented 6 years ago

Thanks @taesung89 , Yes, you are absolutely right, I was also surprised by this. However, it is not happening with all setups, probably because of gcc versions. I am able to reproduce it and will push the fix very soon.

mayankrana commented 6 years ago

Fix is being pushed, it should be there in a few minutes.