我为回归任务建立并训练了我的LSTM模型,一切都很好。我想使用来自cleverhans的fast_gradient_method函数(或任何其他cleverhans函数作为任何其他攻击的代表)。
我不明白我该怎么把模型传递给函数。来自克里弗汉斯:
:param model_fn: a callable that takes an input tensor and returns the model logits无论我给函数输入什么(模型本身、get_weights获得的权重、密集层之前的“阶段”的权重.),我得到了以下错误:
TypeError: 'module' object is not callable什么才是正确的输入才能让它发挥作用?
在我发现的唯一工作示例中,下面的代码行用于定义logits_model,然后将其传递为:param model_fn:,但我仍然得到上面的错误
logits_model = tf.keras.Model(model.input,model.layers[-1].output)发布于 2022-11-14 14:14:40
若要传递有效的模型,应以下列方式定义:
(只是一个例子)
"make“只需要model.summary()才能工作,我在另一篇文章中找到了代码,所以我现在似乎找不到
class modSubclass(Model):
def __init__(self):
super(modSubclass, self).__init__()
self.lstm1 = GRU(hidden_size1, activation='relu',return_sequences=True,input_shape=(input_size,1))
self.lstm2 = GRU(hidden_size2, activation='relu')
self.dense1 = Dense(K, activation='relu')
def call(self,x):
x = self.lstm1(x)
x = self.lstm2(x)
x = self.dense1(x)
return x
def make(self, input_shape):
'''
This method makes the command "model.summary()" work.
input_shape: (H,W,C), do not specify batch B
'''
x = tf.keras.layers.Input(shape=input_shape)
model = tf.keras.Model(inputs=[x], outputs=self.call(x), name='actor')
print(model.summary())
return modelhttps://stackoverflow.com/questions/74391941
复制相似问题