Closed mayfly227 closed 3 years ago
i am not familiar with tensorflow 1.x
You are quite closed to the answer. :+1:
import tensorflow as tf
import tensorflow_hub as hub
from realsafe.model.base import ClassifierWithLogits
from realsafe.utils import get_res_path
def load(session):
model = VGGDEEP()
model.load(session)
return model
class VGGDEEP(ClassifierWithLogits):
def __init__(self):
ClassifierWithLogits.__init__(self,
x_min=0.0, x_max=1.0, x_shape=(32, 32, 3,), x_dtype=tf.float32,
y_dtype=tf.int32, n_class=10)
self.model = hub.Module("https://hub.tensorflow.google.cn/deepmind/ganeval-cifar10-convnet/1")
def _logits_and_labels(self, xs_ph):
logits = self.model(xs_ph)
predicts = tf.nn.softmax(logits)
predicted_labels = tf.argmax(predicts, 1, output_type=tf.int32)
return logits, predicted_labels
def load(self, session):
session.run(tf.variables_initializer(self.model.variables))
Save it to ganeval.py
. To run some basic tests:
python3 -m realsafe.benchmark.prediction_cli --dataset cifar10 --offset 0 --count 1000 --output x.npy --batch-size 100 ganeval.py
You are quite closed to the answer. 👍
import tensorflow as tf import tensorflow_hub as hub from realsafe.model.base import ClassifierWithLogits from realsafe.utils import get_res_path def load(session): model = VGGDEEP() model.load(session) return model class VGGDEEP(ClassifierWithLogits): def __init__(self): ClassifierWithLogits.__init__(self, x_min=0.0, x_max=1.0, x_shape=(32, 32, 3,), x_dtype=tf.float32, y_dtype=tf.int32, n_class=10) self.model = hub.Module("https://hub.tensorflow.google.cn/deepmind/ganeval-cifar10-convnet/1") def _logits_and_labels(self, xs_ph): logits = self.model(xs_ph) predicts = tf.nn.softmax(logits) predicted_labels = tf.argmax(predicts, 1, output_type=tf.int32) return logits, predicted_labels def load(self, session): session.run(tf.variables_initializer(self.model.variables))
Save it to
ganeval.py
. To run some basic tests:python3 -m realsafe.benchmark.prediction_cli --dataset cifar10 --offset 0 --count 1000 --output x.npy --batch-size 100 ganeval.py
very thanks!
i want use other models to generate adversarial samples, but something wrong with it.can you tell me how to do it? This is my code
as you see ,i want to use this model(https://hub.tensorflow.google.cn/deepmind/ganeval-cifar10-convnet/1) to genernate adv samples.