Author | SHA1 | Message | Date |
---|---|---|---|
|
be69ca07d8 |
!177 Update Version Number
From: @pkuliuliu Reviewed-by: @liu_luobin,@zhidanliu,@jxlang910 Signed-off-by: @jxlang910 |
4 years ago |
|
7f98ff468e | add version number 1.1.2 | 4 years ago |
|
c91ff1f641 |
!162 Update version number
From: @pkuliuliu Reviewed-by: @liu_luobin,@jxlang910 Signed-off-by: @jxlang910 |
4 years ago |
|
675c1c25d8 | update version number to 1.1.1 | 4 years ago |
|
32c5ac5d96 |
!160 Change TensorAdd to Add
From: @pkuliuliu Reviewed-by: @jxlang910,@liu_luobin Signed-off-by: @jxlang910 |
4 years ago |
|
4ca8b5feee | change TensorAdd to Add | 4 years ago |
@@ -224,7 +224,7 @@ class ResidualBlockUsing(nn.Cell): | |||||
self.bn_down_sample = self.bn_down_sample.set_train() | self.bn_down_sample = self.bn_down_sample.set_train() | ||||
if not weights_update: | if not weights_update: | ||||
self.conv_down_sample.weight.requires_grad = False | self.conv_down_sample.weight.requires_grad = False | ||||
self.add = P.TensorAdd() | |||||
self.add = P.Add() | |||||
def construct(self, x): | def construct(self, x): | ||||
identity = x | identity = x | ||||
@@ -64,7 +64,7 @@ class ResidualBlock(nn.Cell): | |||||
out_chls = out_channels//2 | out_chls = out_channels//2 | ||||
self.conv1 = conv_block(in_channels, out_chls, kernel_size=1, stride=1) | self.conv1 = conv_block(in_channels, out_chls, kernel_size=1, stride=1) | ||||
self.conv2 = conv_block(out_chls, out_channels, kernel_size=3, stride=1) | self.conv2 = conv_block(out_chls, out_channels, kernel_size=3, stride=1) | ||||
self.add = P.TensorAdd() | |||||
self.add = P.Add() | |||||
def construct(self, x): | def construct(self, x): | ||||
identity = x | identity = x | ||||
@@ -22,7 +22,7 @@ from mindspore import context | |||||
from mindspore import nn | from mindspore import nn | ||||
from mindspore.nn import Cell | from mindspore.nn import Cell | ||||
from mindspore.nn import SoftmaxCrossEntropyWithLogits | from mindspore.nn import SoftmaxCrossEntropyWithLogits | ||||
from mindspore.ops.operations import TensorAdd | |||||
from mindspore.ops.operations import Add | |||||
from mindspore.train.serialization import load_checkpoint, load_param_into_net | from mindspore.train.serialization import load_checkpoint, load_param_into_net | ||||
from scipy.special import softmax | from scipy.special import softmax | ||||
@@ -58,7 +58,7 @@ class EncoderNet(Cell): | |||||
def __init__(self, encode_dim): | def __init__(self, encode_dim): | ||||
super(EncoderNet, self).__init__() | super(EncoderNet, self).__init__() | ||||
self._encode_dim = encode_dim | self._encode_dim = encode_dim | ||||
self.add = TensorAdd() | |||||
self.add = Add() | |||||
def construct(self, inputs): | def construct(self, inputs): | ||||
""" | """ | ||||
@@ -18,7 +18,7 @@ from mindspore import Model | |||||
from mindspore import Tensor | from mindspore import Tensor | ||||
from mindspore import context | from mindspore import context | ||||
from mindspore.nn import Cell | from mindspore.nn import Cell | ||||
from mindspore.ops.operations import TensorAdd | |||||
from mindspore.ops.operations import Add | |||||
from mindspore.train.serialization import load_checkpoint, load_param_into_net | from mindspore.train.serialization import load_checkpoint, load_param_into_net | ||||
from mindarmour import BlackModel | from mindarmour import BlackModel | ||||
@@ -72,7 +72,7 @@ class EncoderNet(Cell): | |||||
def __init__(self, encode_dim): | def __init__(self, encode_dim): | ||||
super(EncoderNet, self).__init__() | super(EncoderNet, self).__init__() | ||||
self._encode_dim = encode_dim | self._encode_dim = encode_dim | ||||
self.add = TensorAdd() | |||||
self.add = Add() | |||||
def construct(self, inputs): | def construct(self, inputs): | ||||
""" | """ | ||||
@@ -325,7 +325,7 @@ class _MechanismsParamsUpdater(Cell): | |||||
self._init_noise_multiplier = init_noise_multiplier | self._init_noise_multiplier = init_noise_multiplier | ||||
self._div = P.Div() | self._div = P.Div() | ||||
self._add = P.TensorAdd() | |||||
self._add = P.Add() | |||||
self._assign = P.Assign() | self._assign = P.Assign() | ||||
self._sub = P.Sub() | self._sub = P.Sub() | ||||
self._one = Tensor(1, mstype.float32) | self._one = Tensor(1, mstype.float32) | ||||
@@ -414,7 +414,7 @@ class AdaClippingWithGaussianRandom(Cell): | |||||
mstype.float32) | mstype.float32) | ||||
self._zero = Tensor(0, mstype.float32) | self._zero = Tensor(0, mstype.float32) | ||||
self._add = P.TensorAdd() | |||||
self._add = P.Add() | |||||
self._sub = P.Sub() | self._sub = P.Sub() | ||||
self._mul = P.Mul() | self._mul = P.Mul() | ||||
self._exp = P.Exp() | self._exp = P.Exp() | ||||
@@ -42,7 +42,7 @@ def tensor_grad_scale(scale, grad): | |||||
class _TupleAdd(nn.Cell): | class _TupleAdd(nn.Cell): | ||||
def __init__(self): | def __init__(self): | ||||
super(_TupleAdd, self).__init__() | super(_TupleAdd, self).__init__() | ||||
self.add = P.TensorAdd() | |||||
self.add = P.Add() | |||||
self.hyper_map = C.HyperMap() | self.hyper_map = C.HyperMap() | ||||
def construct(self, input1, input2): | def construct(self, input1, input2): | ||||
@@ -323,7 +323,7 @@ class _ClipGradients(nn.Cell): | |||||
class _TupleAdd(nn.Cell): | class _TupleAdd(nn.Cell): | ||||
def __init__(self): | def __init__(self): | ||||
super(_TupleAdd, self).__init__() | super(_TupleAdd, self).__init__() | ||||
self.add = P.TensorAdd() | |||||
self.add = P.Add() | |||||
self.hyper_map = C.HyperMap() | self.hyper_map = C.HyperMap() | ||||
def construct(self, input1, input2): | def construct(self, input1, input2): | ||||
@@ -422,7 +422,7 @@ class _TrainOneStepWithLossScaleCell(Cell): | |||||
self._clip_by_global_norm = _ClipGradients() | self._clip_by_global_norm = _ClipGradients() | ||||
self._noise_mech = noise_mech | self._noise_mech = noise_mech | ||||
self._clip_mech = clip_mech | self._clip_mech = clip_mech | ||||
self._add = P.TensorAdd() | |||||
self._add = P.Add() | |||||
self._norm = nn.Norm() | self._norm = nn.Norm() | ||||
self._tuple_add = _TupleAdd() | self._tuple_add = _TupleAdd() | ||||
self._hyper_map = C.HyperMap() | self._hyper_map = C.HyperMap() | ||||
@@ -508,7 +508,7 @@ class _TrainOneStepWithLossScaleCell(Cell): | |||||
GRADIENT_CLIP_TYPE, | GRADIENT_CLIP_TYPE, | ||||
self._norm_bound) | self._norm_bound) | ||||
grads = self._tuple_add(grads, record_grad) | grads = self._tuple_add(grads, record_grad) | ||||
total_loss = P.TensorAdd()(total_loss, loss) | |||||
total_loss = P.Add()(total_loss, loss) | |||||
loss = P.Div()(total_loss, self._micro_float) | loss = P.Div()(total_loss, self._micro_float) | ||||
beta = self._div(beta, self._micro_batches) | beta = self._div(beta, self._micro_batches) | ||||
@@ -626,7 +626,7 @@ class _TrainOneStepCell(Cell): | |||||
self._noise_mech = noise_mech | self._noise_mech = noise_mech | ||||
self._clip_mech = clip_mech | self._clip_mech = clip_mech | ||||
self._tuple_add = _TupleAdd() | self._tuple_add = _TupleAdd() | ||||
self._add = P.TensorAdd() | |||||
self._add = P.Add() | |||||
self._norm = nn.Norm() | self._norm = nn.Norm() | ||||
self._hyper_map = C.HyperMap() | self._hyper_map = C.HyperMap() | ||||
self._zero = Tensor(0, mstype.float32) | self._zero = Tensor(0, mstype.float32) | ||||
@@ -698,7 +698,7 @@ class _TrainOneStepCell(Cell): | |||||
GRADIENT_CLIP_TYPE, | GRADIENT_CLIP_TYPE, | ||||
self._norm_bound) | self._norm_bound) | ||||
grads = self._tuple_add(grads, record_grad) | grads = self._tuple_add(grads, record_grad) | ||||
total_loss = P.TensorAdd()(total_loss, loss) | |||||
total_loss = P.Add()(total_loss, loss) | |||||
loss = self._div(total_loss, self._micro_float) | loss = self._div(total_loss, self._micro_float) | ||||
if self._noise_mech is not None: | if self._noise_mech is not None: | ||||
@@ -18,7 +18,7 @@ from setuptools import setup | |||||
from setuptools.command.egg_info import egg_info | from setuptools.command.egg_info import egg_info | ||||
from setuptools.command.build_py import build_py | from setuptools.command.build_py import build_py | ||||
version = '1.1.0' | |||||
version = '1.1.2' | |||||
cur_dir = os.path.dirname(os.path.realpath(__file__)) | cur_dir = os.path.dirname(os.path.realpath(__file__)) | ||||
pkg_dir = os.path.join(cur_dir, 'build') | pkg_dir = os.path.join(cur_dir, 'build') | ||||
@@ -121,7 +121,7 @@ class ResidualBlock(nn.Cell): | |||||
self.bn3 = bn_with_initialize_last(out_channels) | self.bn3 = bn_with_initialize_last(out_channels) | ||||
self.relu = P.ReLU() | self.relu = P.ReLU() | ||||
self.add = P.TensorAdd() | |||||
self.add = P.Add() | |||||
def construct(self, x): | def construct(self, x): | ||||
identity = x | identity = x | ||||
@@ -168,7 +168,7 @@ class ResidualBlockWithDown(nn.Cell): | |||||
self.conv_down_sample = conv1x1(in_channels, out_channels, stride=stride, padding=0) | self.conv_down_sample = conv1x1(in_channels, out_channels, stride=stride, padding=0) | ||||
self.bn_down_sample = bn_with_initialize(out_channels) | self.bn_down_sample = bn_with_initialize(out_channels) | ||||
self.add = P.TensorAdd() | |||||
self.add = P.Add() | |||||
def construct(self, x): | def construct(self, x): | ||||
identity = x | identity = x | ||||
@@ -20,7 +20,7 @@ import pytest | |||||
from mindspore.nn import Cell | from mindspore.nn import Cell | ||||
from mindspore import Model | from mindspore import Model | ||||
from mindspore import context | from mindspore import context | ||||
from mindspore.ops.operations import TensorAdd | |||||
from mindspore.ops.operations import Add | |||||
from mindarmour.adv_robustness.detectors import SimilarityDetector | from mindarmour.adv_robustness.detectors import SimilarityDetector | ||||
@@ -35,7 +35,7 @@ class EncoderNet(Cell): | |||||
def __init__(self, encode_dim): | def __init__(self, encode_dim): | ||||
super(EncoderNet, self).__init__() | super(EncoderNet, self).__init__() | ||||
self._encode_dim = encode_dim | self._encode_dim = encode_dim | ||||
self.add = TensorAdd() | |||||
self.add = Add() | |||||
def construct(self, inputs): | def construct(self, inputs): | ||||
""" | """ | ||||
@@ -18,7 +18,7 @@ import numpy as np | |||||
import pytest | import pytest | ||||
from mindspore.nn import Cell | from mindspore.nn import Cell | ||||
from mindspore.ops.operations import TensorAdd | |||||
from mindspore.ops.operations import Add | |||||
from mindspore.train.model import Model | from mindspore.train.model import Model | ||||
from mindspore import context | from mindspore import context | ||||
@@ -35,7 +35,7 @@ class Net(Cell): | |||||
""" | """ | ||||
def __init__(self): | def __init__(self): | ||||
super(Net, self).__init__() | super(Net, self).__init__() | ||||
self.add = TensorAdd() | |||||
self.add = Add() | |||||
def construct(self, inputs): | def construct(self, inputs): | ||||
""" | """ | ||||
@@ -53,7 +53,7 @@ class AutoNet(Cell): | |||||
""" | """ | ||||
def __init__(self): | def __init__(self): | ||||
super(AutoNet, self).__init__() | super(AutoNet, self).__init__() | ||||
self.add = TensorAdd() | |||||
self.add = Add() | |||||
def construct(self, inputs): | def construct(self, inputs): | ||||
""" | """ | ||||
@@ -19,7 +19,7 @@ import pytest | |||||
import mindspore.ops.operations as P | import mindspore.ops.operations as P | ||||
from mindspore.nn import Cell | from mindspore.nn import Cell | ||||
from mindspore.ops.operations import TensorAdd | |||||
from mindspore.ops.operations import Add | |||||
from mindspore import Model | from mindspore import Model | ||||
from mindspore import context | from mindspore import context | ||||
@@ -36,7 +36,7 @@ class Net(Cell): | |||||
def __init__(self): | def __init__(self): | ||||
super(Net, self).__init__() | super(Net, self).__init__() | ||||
self.add = TensorAdd() | |||||
self.add = Add() | |||||
def construct(self, inputs): | def construct(self, inputs): | ||||
""" | """ | ||||
@@ -20,7 +20,7 @@ import pytest | |||||
from mindspore.nn import Cell | from mindspore.nn import Cell | ||||
from mindspore import Model | from mindspore import Model | ||||
from mindspore import context | from mindspore import context | ||||
from mindspore.ops.operations import TensorAdd | |||||
from mindspore.ops.operations import Add | |||||
from mindarmour.adv_robustness.detectors import RegionBasedDetector | from mindarmour.adv_robustness.detectors import RegionBasedDetector | ||||
@@ -34,7 +34,7 @@ class Net(Cell): | |||||
""" | """ | ||||
def __init__(self): | def __init__(self): | ||||
super(Net, self).__init__() | super(Net, self).__init__() | ||||
self.add = TensorAdd() | |||||
self.add = Add() | |||||
def construct(self, inputs): | def construct(self, inputs): | ||||
""" | """ | ||||
@@ -29,8 +29,10 @@ from mindarmour.privacy.diff_privacy import DPOptimizerClassFactory | |||||
from ut.python.utils.mock_net import Net | from ut.python.utils.mock_net import Net | ||||
def dataset_generator(batch_size, batches): | |||||
def dataset_generator(): | |||||
"""mock training data.""" | """mock training data.""" | ||||
batch_size = 32 | |||||
batches = 128 | |||||
data = np.random.random((batches*batch_size, 1, 32, 32)).astype( | data = np.random.random((batches*batch_size, 1, 32, 32)).astype( | ||||
np.float32) | np.float32) | ||||
label = np.random.randint(0, 10, batches*batch_size).astype(np.int32) | label = np.random.randint(0, 10, batches*batch_size).astype(np.int32) | ||||
@@ -49,8 +51,6 @@ def test_dp_model_with_pynative_mode(): | |||||
norm_bound = 1.0 | norm_bound = 1.0 | ||||
initial_noise_multiplier = 0.01 | initial_noise_multiplier = 0.01 | ||||
network = Net() | network = Net() | ||||
batch_size = 32 | |||||
batches = 128 | |||||
epochs = 1 | epochs = 1 | ||||
micro_batches = 2 | micro_batches = 2 | ||||
loss = nn.SoftmaxCrossEntropyWithLogits(sparse=True) | loss = nn.SoftmaxCrossEntropyWithLogits(sparse=True) | ||||
@@ -73,7 +73,7 @@ def test_dp_model_with_pynative_mode(): | |||||
loss_fn=loss, | loss_fn=loss, | ||||
optimizer=net_opt, | optimizer=net_opt, | ||||
metrics=None) | metrics=None) | ||||
ms_ds = ds.GeneratorDataset(dataset_generator(batch_size, batches), | |||||
ms_ds = ds.GeneratorDataset(dataset_generator, | |||||
['data', 'label']) | ['data', 'label']) | ||||
model.train(epochs, ms_ds, dataset_sink_mode=False) | model.train(epochs, ms_ds, dataset_sink_mode=False) | ||||
@@ -88,8 +88,6 @@ def test_dp_model_with_graph_mode(): | |||||
norm_bound = 1.0 | norm_bound = 1.0 | ||||
initial_noise_multiplier = 0.01 | initial_noise_multiplier = 0.01 | ||||
network = Net() | network = Net() | ||||
batch_size = 32 | |||||
batches = 128 | |||||
epochs = 1 | epochs = 1 | ||||
loss = nn.SoftmaxCrossEntropyWithLogits(sparse=True) | loss = nn.SoftmaxCrossEntropyWithLogits(sparse=True) | ||||
noise_mech = NoiseMechanismsFactory().create('Gaussian', | noise_mech = NoiseMechanismsFactory().create('Gaussian', | ||||
@@ -110,7 +108,7 @@ def test_dp_model_with_graph_mode(): | |||||
loss_fn=loss, | loss_fn=loss, | ||||
optimizer=net_opt, | optimizer=net_opt, | ||||
metrics=None) | metrics=None) | ||||
ms_ds = ds.GeneratorDataset(dataset_generator(batch_size, batches), | |||||
ms_ds = ds.GeneratorDataset(dataset_generator, | |||||
['data', 'label']) | ['data', 'label']) | ||||
model.train(epochs, ms_ds, dataset_sink_mode=False) | model.train(epochs, ms_ds, dataset_sink_mode=False) | ||||
@@ -125,8 +123,6 @@ def test_dp_model_with_graph_mode_ada_gaussian(): | |||||
norm_bound = 1.0 | norm_bound = 1.0 | ||||
initial_noise_multiplier = 0.01 | initial_noise_multiplier = 0.01 | ||||
network = Net() | network = Net() | ||||
batch_size = 32 | |||||
batches = 128 | |||||
epochs = 1 | epochs = 1 | ||||
alpha = 0.8 | alpha = 0.8 | ||||
loss = nn.SoftmaxCrossEntropyWithLogits(sparse=True) | loss = nn.SoftmaxCrossEntropyWithLogits(sparse=True) | ||||
@@ -146,6 +142,6 @@ def test_dp_model_with_graph_mode_ada_gaussian(): | |||||
loss_fn=loss, | loss_fn=loss, | ||||
optimizer=net_opt, | optimizer=net_opt, | ||||
metrics=None) | metrics=None) | ||||
ms_ds = ds.GeneratorDataset(dataset_generator(batch_size, batches), | |||||
ms_ds = ds.GeneratorDataset(dataset_generator, | |||||
['data', 'label']) | ['data', 'label']) | ||||
model.train(epochs, ms_ds, dataset_sink_mode=False) | model.train(epochs, ms_ds, dataset_sink_mode=False) |
@@ -31,7 +31,9 @@ LOGGER = LogUtil.get_instance() | |||||
TAG = 'DP-Monitor Test' | TAG = 'DP-Monitor Test' | ||||
def dataset_generator(batch_size, batches): | |||||
def dataset_generator(): | |||||
batch_size = 16 | |||||
batches = 128 | |||||
data = np.random.random((batches * batch_size, 1, 32, 32)).astype( | data = np.random.random((batches * batch_size, 1, 32, 32)).astype( | ||||
np.float32) | np.float32) | ||||
label = np.random.randint(0, 10, batches * batch_size).astype(np.int32) | label = np.random.randint(0, 10, batches * batch_size).astype(np.int32) | ||||
@@ -48,7 +50,6 @@ def dataset_generator(batch_size, batches): | |||||
def test_dp_monitor(): | def test_dp_monitor(): | ||||
context.set_context(mode=context.GRAPH_MODE, device_target="Ascend") | context.set_context(mode=context.GRAPH_MODE, device_target="Ascend") | ||||
batch_size = 16 | batch_size = 16 | ||||
batches = 128 | |||||
epochs = 1 | epochs = 1 | ||||
rdp = PrivacyMonitorFactory.create(policy='rdp', num_samples=60000, | rdp = PrivacyMonitorFactory.create(policy='rdp', num_samples=60000, | ||||
batch_size=batch_size, | batch_size=batch_size, | ||||
@@ -64,7 +65,7 @@ def test_dp_monitor(): | |||||
model = Model(network, net_loss, net_opt) | model = Model(network, net_loss, net_opt) | ||||
LOGGER.info(TAG, "============== Starting Training ==============") | LOGGER.info(TAG, "============== Starting Training ==============") | ||||
ds1 = ds.GeneratorDataset(dataset_generator(batch_size, batches), | |||||
ds1 = ds.GeneratorDataset(dataset_generator, | |||||
["data", "label"]) | ["data", "label"]) | ||||
model.train(epochs, ds1, callbacks=[rdp], dataset_sink_mode=False) | model.train(epochs, ds1, callbacks=[rdp], dataset_sink_mode=False) | ||||
@@ -76,7 +77,6 @@ def test_dp_monitor(): | |||||
def test_dp_monitor_gpu(): | def test_dp_monitor_gpu(): | ||||
context.set_context(mode=context.GRAPH_MODE, device_target="GPU") | context.set_context(mode=context.GRAPH_MODE, device_target="GPU") | ||||
batch_size = 16 | batch_size = 16 | ||||
batches = 128 | |||||
epochs = 1 | epochs = 1 | ||||
rdp = PrivacyMonitorFactory.create(policy='rdp', num_samples=60000, | rdp = PrivacyMonitorFactory.create(policy='rdp', num_samples=60000, | ||||
batch_size=batch_size, | batch_size=batch_size, | ||||
@@ -92,7 +92,7 @@ def test_dp_monitor_gpu(): | |||||
model = Model(network, net_loss, net_opt) | model = Model(network, net_loss, net_opt) | ||||
LOGGER.info(TAG, "============== Starting Training ==============") | LOGGER.info(TAG, "============== Starting Training ==============") | ||||
ds1 = ds.GeneratorDataset(dataset_generator(batch_size, batches), | |||||
ds1 = ds.GeneratorDataset(dataset_generator, | |||||
["data", "label"]) | ["data", "label"]) | ||||
model.train(epochs, ds1, callbacks=[rdp], dataset_sink_mode=False) | model.train(epochs, ds1, callbacks=[rdp], dataset_sink_mode=False) | ||||
@@ -104,7 +104,6 @@ def test_dp_monitor_gpu(): | |||||
def test_dp_monitor_cpu(): | def test_dp_monitor_cpu(): | ||||
context.set_context(mode=context.GRAPH_MODE, device_target="CPU") | context.set_context(mode=context.GRAPH_MODE, device_target="CPU") | ||||
batch_size = 16 | batch_size = 16 | ||||
batches = 128 | |||||
epochs = 1 | epochs = 1 | ||||
rdp = PrivacyMonitorFactory.create(policy='rdp', num_samples=60000, | rdp = PrivacyMonitorFactory.create(policy='rdp', num_samples=60000, | ||||
batch_size=batch_size, | batch_size=batch_size, | ||||
@@ -120,7 +119,7 @@ def test_dp_monitor_cpu(): | |||||
model = Model(network, net_loss, net_opt) | model = Model(network, net_loss, net_opt) | ||||
LOGGER.info(TAG, "============== Starting Training ==============") | LOGGER.info(TAG, "============== Starting Training ==============") | ||||
ds1 = ds.GeneratorDataset(dataset_generator(batch_size, batches), | |||||
ds1 = ds.GeneratorDataset(dataset_generator, | |||||
["data", "label"]) | ["data", "label"]) | ||||
model.train(epochs, ds1, callbacks=[rdp], dataset_sink_mode=False) | model.train(epochs, ds1, callbacks=[rdp], dataset_sink_mode=False) | ||||
@@ -133,7 +132,6 @@ def test_dp_monitor_cpu(): | |||||
def test_dp_monitor_zcdp(): | def test_dp_monitor_zcdp(): | ||||
context.set_context(mode=context.GRAPH_MODE, device_target="Ascend") | context.set_context(mode=context.GRAPH_MODE, device_target="Ascend") | ||||
batch_size = 16 | batch_size = 16 | ||||
batches = 128 | |||||
epochs = 1 | epochs = 1 | ||||
zcdp = PrivacyMonitorFactory.create(policy='zcdp', num_samples=60000, | zcdp = PrivacyMonitorFactory.create(policy='zcdp', num_samples=60000, | ||||
batch_size=batch_size, | batch_size=batch_size, | ||||
@@ -149,7 +147,7 @@ def test_dp_monitor_zcdp(): | |||||
model = Model(network, net_loss, net_opt) | model = Model(network, net_loss, net_opt) | ||||
LOGGER.info(TAG, "============== Starting Training ==============") | LOGGER.info(TAG, "============== Starting Training ==============") | ||||
ds1 = ds.GeneratorDataset(dataset_generator(batch_size, batches), | |||||
ds1 = ds.GeneratorDataset(dataset_generator, | |||||
["data", "label"]) | ["data", "label"]) | ||||
model.train(epochs, ds1, callbacks=[zcdp], dataset_sink_mode=False) | model.train(epochs, ds1, callbacks=[zcdp], dataset_sink_mode=False) | ||||
@@ -161,7 +159,6 @@ def test_dp_monitor_zcdp(): | |||||
def test_dp_monitor_zcdp_gpu(): | def test_dp_monitor_zcdp_gpu(): | ||||
context.set_context(mode=context.GRAPH_MODE, device_target="GPU") | context.set_context(mode=context.GRAPH_MODE, device_target="GPU") | ||||
batch_size = 16 | batch_size = 16 | ||||
batches = 128 | |||||
epochs = 1 | epochs = 1 | ||||
zcdp = PrivacyMonitorFactory.create(policy='zcdp', num_samples=60000, | zcdp = PrivacyMonitorFactory.create(policy='zcdp', num_samples=60000, | ||||
batch_size=batch_size, | batch_size=batch_size, | ||||
@@ -177,7 +174,7 @@ def test_dp_monitor_zcdp_gpu(): | |||||
model = Model(network, net_loss, net_opt) | model = Model(network, net_loss, net_opt) | ||||
LOGGER.info(TAG, "============== Starting Training ==============") | LOGGER.info(TAG, "============== Starting Training ==============") | ||||
ds1 = ds.GeneratorDataset(dataset_generator(batch_size, batches), | |||||
ds1 = ds.GeneratorDataset(dataset_generator, | |||||
["data", "label"]) | ["data", "label"]) | ||||
model.train(epochs, ds1, callbacks=[zcdp], dataset_sink_mode=False) | model.train(epochs, ds1, callbacks=[zcdp], dataset_sink_mode=False) | ||||
@@ -189,7 +186,6 @@ def test_dp_monitor_zcdp_gpu(): | |||||
def test_dp_monitor_zcdp_cpu(): | def test_dp_monitor_zcdp_cpu(): | ||||
context.set_context(mode=context.GRAPH_MODE, device_target="CPU") | context.set_context(mode=context.GRAPH_MODE, device_target="CPU") | ||||
batch_size = 16 | batch_size = 16 | ||||
batches = 128 | |||||
epochs = 1 | epochs = 1 | ||||
zcdp = PrivacyMonitorFactory.create(policy='zcdp', num_samples=60000, | zcdp = PrivacyMonitorFactory.create(policy='zcdp', num_samples=60000, | ||||
batch_size=batch_size, | batch_size=batch_size, | ||||
@@ -205,6 +201,6 @@ def test_dp_monitor_zcdp_cpu(): | |||||
model = Model(network, net_loss, net_opt) | model = Model(network, net_loss, net_opt) | ||||
LOGGER.info(TAG, "============== Starting Training ==============") | LOGGER.info(TAG, "============== Starting Training ==============") | ||||
ds1 = ds.GeneratorDataset(dataset_generator(batch_size, batches), | |||||
ds1 = ds.GeneratorDataset(dataset_generator, | |||||
["data", "label"]) | ["data", "label"]) | ||||
model.train(epochs, ds1, callbacks=[zcdp], dataset_sink_mode=False) | model.train(epochs, ds1, callbacks=[zcdp], dataset_sink_mode=False) |
@@ -31,8 +31,10 @@ from ut.python.utils.mock_net import Net | |||||
context.set_context(mode=context.GRAPH_MODE) | context.set_context(mode=context.GRAPH_MODE) | ||||
def dataset_generator(batch_size, batches): | |||||
def dataset_generator(): | |||||
"""mock training data.""" | """mock training data.""" | ||||
batch_size = 16 | |||||
batches = 1 | |||||
data = np.random.randn(batches*batch_size, 1, 32, 32).astype( | data = np.random.randn(batches*batch_size, 1, 32, 32).astype( | ||||
np.float32) | np.float32) | ||||
label = np.random.randint(0, 10, batches*batch_size).astype(np.int32) | label = np.random.randint(0, 10, batches*batch_size).astype(np.int32) | ||||
@@ -74,11 +76,9 @@ def test_membership_inference_object_train(): | |||||
"n_neighbors": [3, 5, 7], | "n_neighbors": [3, 5, 7], | ||||
} | } | ||||
}] | }] | ||||
batch_size = 16 | |||||
batches = 1 | |||||
ds_train = ds.GeneratorDataset(dataset_generator(batch_size, batches), | |||||
ds_train = ds.GeneratorDataset(dataset_generator, | |||||
["image", "label"]) | ["image", "label"]) | ||||
ds_test = ds.GeneratorDataset(dataset_generator(batch_size, batches), | |||||
ds_test = ds.GeneratorDataset(dataset_generator, | |||||
["image", "label"]) | ["image", "label"]) | ||||
inference_model.train(ds_train, ds_test, config) | inference_model.train(ds_train, ds_test, config) | ||||
@@ -96,11 +96,9 @@ def test_membership_inference_eval(): | |||||
inference_model = MembershipInference(model, -1) | inference_model = MembershipInference(model, -1) | ||||
assert isinstance(inference_model, MembershipInference) | assert isinstance(inference_model, MembershipInference) | ||||
batch_size = 16 | |||||
batches = 1 | |||||
eval_train = ds.GeneratorDataset(dataset_generator(batch_size, batches), | |||||
eval_train = ds.GeneratorDataset(dataset_generator, | |||||
["image", "label"]) | ["image", "label"]) | ||||
eval_test = ds.GeneratorDataset(dataset_generator(batch_size, batches), | |||||
eval_test = ds.GeneratorDataset(dataset_generator, | |||||
["image", "label"]) | ["image", "label"]) | ||||
metrics = ["precision", "accuracy", "recall"] | metrics = ["precision", "accuracy", "recall"] | ||||