我正在尝试对回归模型实施cleverhans 攻击。我的模型有 2 个因变量。
checkpointer = ModelCheckpoint(filepath="/content/drive/My Drive/Colab Notebooks/best_weights.hdf5", verbose=0, save_best_only=True) # save best model
model = Sequential()
model.add(Dense(60, input_dim=X.shape[1], activation='linear'))
model.add(Dense(30, activation='relu'))
model.add(Dense(10, activation='relu'))
model.add(Dense(5, activation='linear'))
model.add(Dense(2,activation='linear')) # Output
model.compile(loss='mean_absolute_error', optimizer='adam', metrics=['mae'])
monitor = EarlyStopping(monitor='val_loss', min_delta=1e-3, patience=5, verbose=1, mode='auto')
history = model.fit(x_train, y_train, validation_data=(x_test,y_test), callbacks=[monitor,checkpointer], verbose=1, epochs=20, batch_size=128)
model.summary()
我正在使用cleverhans 2.1.0 tensorflow 1.15 也尝试了新版本。我的攻击代码是
wrap = KerasModelWrapper(model)
#Implementing the FGSM attack
#FGM Instance on trained classifier from Part 1
fgsm = FastGradientMethod(wrap, sess=sess)
#Attack parameters
fgsm_params = {'eps':0.05, 'clip_min':0.0, 'clip_max':1.0}
#Generate adversarial data
fgsm_adv_data_test = fgsm.generate_np(x_test, **fgsm_params)
#Evaluate accuracy on target classifier
fgsm_adv_score = model_classifier.evaluate(fgsm_adv_data_test, y_test)
在此之后我收到一个错误 no softmx 。那么,我是否必须遵循其他步骤。请帮助。