当我尝试将模型还原到foolbox模型时,我收到TypeError: input must be a dictionary
错误。我不确定这个错误是指什么或如何修复它因为我不理解错误。我试图按照发布的代码here
这项考试在第25行投掷:
model.session.run( model.session, "/tmp/models/convnet_maxpool.ckpt" )
这是我正在使用的代码:
import foolbox
import tensorflow as tf
import numpy as np
inputs = tf.placeholder(tf.float32, shape=(None, 784))
logits = tf.layers.dense(inputs, 10)
init_op = tf.global_variables_initializer()
np.random.seed(2)
W = np.random.rand(784, 10).astype(np.float32)
assign_op = tf.assign(tf.global_variables()[0], W)
np.random.seed(22)
example_input = np.random.rand(784)
with foolbox.models.TensorFlowModel(inputs, logits, (0, 1)) as model:
attack = foolbox.attacks.FGSM(model)
model.session.run(init_op)
model.session.run( model.session, "/tmp/models/convnet_maxpool.ckpt" ) # replace with restorer
example_label = np.argmax(model.predictions(example_input))
print(example_label)
adversarial = attack(example_input, example_label, unpack=False)
print(np.argmax(model.predictions(adversarial.image)))
print(adversarial.distance)
是这个错误,因为我正在恢复错误或因为我做错了什么?
答案 0 :(得分:0)
在我看来,以下是正确的:
saver.restore(model.session, "/tmp/models/convnet_maxpool.ckpt")
而不是你的那个:
model.session.run( saver.restore(tf.Session(), "/tmp/models/convnet_maxpool.ckpt" ) )