The following model, which reads a file using one of the APIs specified in the paper, is not caught by the TensorDetected
Model creation example, which reads a file with a single digit number and multiplies the input with it. It works perfectly, yet not being detected by the TensorDetected
import tensorflow as tf
class MaliciousModel(tf.Module):
def __init__(self):
super().__init__()
self.a = tf.Variable(3.0) # Normal-looking model variable
@tf.function
def __call__(self, x):
# Use tf.data API to read from file indirectly
dataset =tf.compat.v1.raw_ops.FixedLengthRecordDatasetV2(
filenames=["/Users/user/test.txt"],
record_bytes=1,
header_bytes=0,
footer_bytes=0,
buffer_size=1024,
compression_type="",
).map(lambda x: tf.strings.to_number(x, out_type=tf.float32))
# Take the first value from the dataset
multiplier = next(iter(dataset)) # Extract first value
return multiplier * x # Perform multiplication
# Create an instance of the model
model = MaliciousModel()
export_dir = "./saved_malicious_model"
tf.saved_model.save(model, export_dir)
print("Model saved!")
['VarHandleOp', 'ReadVariableOp', 'Placeholder', 'StatefulPartitionedCall', 'NoOp', 'Const', 'Placeholder', 'StatefulPartitionedCall', 'StatefulPartitionedCall', 'StatefulPartitionedCall', 'Identity', 'NoOp', 'Const', 'Const', 'RestoreV2', 'Identity', 'AssignVariableOp', 'NoOp', 'Identity', 'Identity', 'NoOp', 'EagerPyFunc', 'Mul', 'Identity', 'NoOp', 'StaticRegexFullMatch', 'Const', 'Const', 'Select', 'StringJoin', 'DisableCopyOnRead', 'ReadVariableOp', 'Identity', 'Identity', 'Const', 'Const', 'ShardedFilename', 'Const', 'Const', 'SaveV2', 'Pack', 'MergeV2Checkpoints', 'Identity', 'Identity', 'NoOp']
The following model, which reads a file using one of the APIs specified in the paper, is not caught by the
TensorDetectedModel creation example, which reads a file with a single digit number and multiplies the input with it. It works perfectly, yet not being detected by the TensorDetected
Looking at the code, it seems the saved model does not include the
FixedLengthRecordDatasetV2API for some reason, but rather the following operator namesCan you please advise why this malicious model was not detected?