peikexin9 / deepxplore

DeepXplore code release
MIT License
393 stars 146 forks source link

Getting Error message while running imageNet. #21

Closed KVRMtech closed 4 years ago

KVRMtech commented 5 years ago

Hi, I am trying to run the ImageNet but am getting error message like Traceback (most Recent call last): File "gen_diff.py" line 53, in

img_pahts = image.list_pictures('./seeds', ext ='JPEG')

Attribute Error: 'Module' object has no attribute 'list_pictures'

RamyaRaghuraman commented 5 years ago

@KVRMtech Did you find a solution?

secureaiexplorer commented 4 years ago

Here is the diff that worked for me in case others need it:

diff --git a/ImageNet/gen_diff.py b/ImageNet/gen_diff.py
index c48a40d..2534578 100644
--- a/ImageNet/gen_diff.py
+++ b/ImageNet/gen_diff.py
@@ -5,12 +5,13 @@ usage: python gen_diff.py -h
 from __future__ import print_function

 import argparse
+import scipy.misc

 from keras.applications.resnet50 import ResNet50
 from keras.applications.vgg16 import VGG16
 from keras.applications.vgg19 import VGG19
 from keras.layers import Input
-from scipy.misc import imsave
+

 from configs import bcolors
 from utils import *
@@ -50,7 +51,7 @@ model_layer_dict1, model_layer_dict2, model_layer_dict3 = init_coverage_tables(m

 # ==============================================================================================
 # start gen inputs
-img_paths = image.list_pictures('./seeds', ext='JPEG')
+img_paths = image.list_pictures('./seeds/', ext='jpeg')
 for _ in xrange(args.seeds):
     gen_img = preprocess_image(random.choice(img_paths))
     orig_img = gen_img.copy()
@@ -81,7 +82,7 @@ for _ in xrange(args.seeds):
         gen_img_deprocessed = deprocess_image(gen_img)

         # save the result to disk
-        imsave('./generated_inputs/' + 'already_differ_' + decode_label(pred1) + '_' + decode_label(
+        scipy.misc.imsave('./generated_inputs/' + 'already_differ_' + decode_label(pred1) + '_' + decode_label(
             pred2) + '_' + decode_label(pred3) + '.png',
                gen_img_deprocessed)
         continue
@@ -155,8 +156,8 @@ for _ in xrange(args.seeds):
             orig_img_deprocessed = deprocess_image(orig_img)

             # save the result to disk
-            imsave('./generated_inputs/' + args.transformation + '_' + decode_label(pred1) + '_' + decode_label(
+            scipy.misc.imsave('./generated_inputs/' + args.transformation + '_' + decode_label(pred1) + '_' + decode_label(
                 pred2) + '_' + decode_label(pred3) + '.png', gen_img_deprocessed)
-            imsave('./generated_inputs/' + args.transformation + '_' + decode_label(pred1) + '_' + decode_label(
+            scipy.misc.imsave('./generated_inputs/' + args.transformation + '_' + decode_label(pred1) + '_' + decode_label(
                 pred2) + '_' + decode_label(pred3) + '_orig.png', orig_img_deprocessed)
             break
diff --git a/ImageNet/utils.py b/ImageNet/utils.py
index 615f268..ac5f4b7 100644
--- a/ImageNet/utils.py
+++ b/ImageNet/utils.py
@@ -5,7 +5,7 @@ import numpy as np
 from keras import backend as K
 from keras.applications.vgg16 import preprocess_input, decode_predictions
 from keras.models import Model
-from keras.preprocessing import image
+from keras_preprocessing import image

 def preprocess_image(img_path):
peikexin9 commented 4 years ago

My apologies for the delayed reply. @KVRMtech @RamyaRaghuraman @mguglani Thank you @mguglani. I have updated the repo according to your fix.