Esempio n. 1
0
        labels.append(labelStore[i])
        path.append(str(i) + ".JPEG")
        idx += 1
        if idx == batch_size:
            yield labels, images, path
            labels = []
            path = []
            images = np.zeros(batch_shape)
            idx = 0
    if idx > 0:
        yield labels, images, path


# Load the Inception model for attributions.
attr_sess, attr_graph = load_model(MODEL_LOC)
inception_predictions_and_gradients = make_predictions_and_gradients(
    attr_sess, attr_graph)
attr_labels = load_labels_vocabulary(LABELS_LOC)
image_iterator = load_images(imagePathOrig, batch_shape)
attr_iterator = load_images(attrPath, batch_shape)

power = [75]
print(len(power))

counterSame = 0
counterPert = 0

crossEntropyStore = np.zeros((len(power), 1000))
countStore = np.zeros((len(power), 1000))
sameFlag = np.zeros(1000)

flipProbStore = np.zeros((len(power), 1000))
Esempio n. 2
0
from InceptionModel.inception_utils import load_model, load_labels_vocabulary, make_predictions_and_gradients, top_label_id_and_score
from IntegratedGradients.integrated_gradients import integrated_gradients, random_baseline_integrated_gradients
from VisualizationLibrary.visualization_lib import Visualize, show_pil_image, pil_image


MODEL_LOC='./InceptionModel/tensorflow_inception_graph.pb'
LABELS_LOC='./InceptionModel/imagenet_comp_graph_label_strings.txt'

# Load the Inception model.
sess, graph = load_model(MODEL_LOC)

# Load the Labels vocabulary.
labels = load_labels_vocabulary(LABELS_LOC)

# Make the predictions_and_gradients function
inception_predictions_and_gradients = make_predictions_and_gradients(sess, graph)



def load_image(img_path):
    # "/Users/pin-jutien/Integrated-Gradients/Images/70bfca4555cca92e.jpg"
    image = tf.image.decode_jpeg(tf.read_file(img_path), channels=3)
    img = sess.run(image)
    return img


img = load_image("/Users/pin-jutien/Integrated-Gradients/Images/70bfca4555cca92e.jpg")

# Determine top label and score.
top_label_id, score = top_label_id_and_score(img, inception_predictions_and_gradients)
print("Top label: %s, score: %f" % (labels[top_label_id], score))