Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit effbb8b

Browse files
acphileUbuntuleezu
authored
Changes to mxnet.metric (#18083)
* finish 5 changes * move metric.py to gluon, replace mx.metric with mx.gluon.metric in python/mxnet/ * fix importError * replace mx.metric with mx.gluon.metric in tests/python * remove global support * remove macro support * rewrite BinaryAccuracy * extend F1 to multiclass/multilabel * add tests for new F1, remove global tests * use mxnet.numpy instead of numpy * fix sanity * rewrite ce and ppl, improve some details * use mxnet.numpy.float64 * remove sklearn * remove reset_local() and get_global in other files * fix test_mlp * replace mx.metric with mx.gluon.metric in example * fix context difference * Disable -DUSE_TVM_OP on GPU builds * Fix disable tvm op for gpu runs * use label.ctx in metric.py; remove gluoncv dependency in test_cvnets * fix sanity * fix importError * remove nose Co-authored-by: Ubuntu <[email protected]> Co-authored-by: Leonard Lausen <[email protected]>
1 parent b4c70eb commit effbb8b

File tree

95 files changed

+938
-867
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+938
-867
lines changed

benchmark/python/sparse/sparse_end2end.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def row_sparse_pull(kv, key, data, slices, weight_array, priority):
225225
learning_rate=0.1, rescale_grad=1.0/batch_size/num_worker)
226226
mod.init_optimizer(optimizer=sgd, kvstore=kv)
227227
# use accuracy as the metric
228-
metric = mx.metric.create('acc')
228+
metric = mx.gluon.metric.create('acc')
229229

230230
index = mod._exec_group.param_names.index('w')
231231
# weight_array bound to executors of the contexts

example/adversary/adversary_generation.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
"epoch = 3\n",
169169
"for e in range(epoch):\n",
170170
" train_loss = 0.\n",
171-
" acc = mx.metric.Accuracy()\n",
171+
" acc = mx.gluon.metric.Accuracy()\n",
172172
" for i, (data, label) in enumerate(train_data):\n",
173173
" data = data.as_in_context(ctx)\n",
174174
" label = label.as_in_context(ctx)\n",
@@ -223,7 +223,7 @@
223223
" l = loss(output, label)\n",
224224
"l.backward()\n",
225225
"\n",
226-
"acc = mx.metric.Accuracy()\n",
226+
"acc = mx.gluon.metric.Accuracy()\n",
227227
"acc.update(label, output)\n",
228228
"\n",
229229
"print(\"Validation batch accuracy {}\".format(acc.get()[1]))"
@@ -256,7 +256,7 @@
256256
"\n",
257257
"output = net(data_perturbated) \n",
258258
"\n",
259-
"acc = mx.metric.Accuracy()\n",
259+
"acc = mx.gluon.metric.Accuracy()\n",
260260
"acc.update(label, output)\n",
261261
"\n",
262262
"print(\"Validation batch accuracy after perturbation {}\".format(acc.get()[1]))"

example/autoencoder/variational_autoencoder/VAE_example.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@
610610
],
611611
"source": [
612612
"# calculate the ELBO which is minus the loss for test set\n",
613-
"metric = mx.metric.Loss()\n",
613+
"metric = mx.gluon.metric.Loss()\n",
614614
"model.score(nd_iter_test, metric)"
615615
]
616616
},

example/caffe/caffe_net.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,6 @@ def parse_args():
140140

141141
# train
142142
if use_caffe_loss:
143-
train_model.fit(args, net, get_iterator(data_shape, use_caffe_data), mx.metric.Caffe())
143+
train_model.fit(args, net, get_iterator(data_shape, use_caffe_data), mx.gluon.metric.Caffe())
144144
else:
145145
train_model.fit(args, net, get_iterator(data_shape, use_caffe_data))

example/caffe/train_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def fit(args, network, data_loader, eval_metrics=None, batch_end_callback=None):
9393
eval_metrics = ['accuracy']
9494
# TopKAccuracy only allows top_k > 1
9595
for top_k in [5, 10, 20]:
96-
eval_metrics.append(mx.metric.create('top_k_accuracy', top_k=top_k))
96+
eval_metrics.append(mx.gluon.metric.create('top_k_accuracy', top_k=top_k))
9797

9898
if batch_end_callback is not None:
9999
if not isinstance(batch_end_callback, list):

example/capsnet/capsulenet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def to4d(img):
122122
return img.reshape(img.shape[0], 1, 28, 28).astype(np.float32)/255
123123

124124

125-
class LossMetric(mx.metric.EvalMetric):
125+
class LossMetric(mx.gluon.metric.EvalMetric):
126126
"""Evaluate the loss function"""
127127
def __init__(self, batch_size, num_gpus):
128128
super(LossMetric, self).__init__('LossMetric')

example/ctc/lstm_ocr_train.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def main():
103103
module.fit(train_data=data_train,
104104
eval_data=data_val,
105105
# use metrics.accuracy or metrics.accuracy_lcs
106-
eval_metric=mx.metric.np(metrics.accuracy, allow_extra_outputs=True),
106+
eval_metric=mx.gluon.metric.np(metrics.accuracy, allow_extra_outputs=True),
107107
optimizer='sgd',
108108
optimizer_params={'learning_rate': hp.learning_rate,
109109
'momentum': hp.momentum,

example/deep-embedded-clustering/autoencoder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def l2_norm(label, pred):
165165
return np.mean(np.square(label-pred))/2.0
166166
solver = Solver(optimizer, momentum=0.9, wd=decay, learning_rate=l_rate,
167167
lr_scheduler=lr_scheduler)
168-
solver.set_metric(mx.metric.CustomMetric(l2_norm))
168+
solver.set_metric(mx.gluon.metric.CustomMetric(l2_norm))
169169
solver.set_monitor(Monitor(print_every))
170170
data_iter = mx.io.NDArrayIter({'data': X}, batch_size=batch_size, shuffle=True,
171171
last_batch_handle='roll_over')
@@ -188,7 +188,7 @@ def l2_norm(label, pred):
188188
return np.mean(np.square(label-pred))/2.0
189189
solver = Solver(optimizer, momentum=0.9, wd=decay, learning_rate=l_rate,
190190
lr_scheduler=lr_scheduler)
191-
solver.set_metric(mx.metric.CustomMetric(l2_norm))
191+
solver.set_metric(mx.gluon.metric.CustomMetric(l2_norm))
192192
solver.set_monitor(Monitor(print_every))
193193
data_iter = mx.io.NDArrayIter({'data': X}, batch_size=batch_size, shuffle=True,
194194
last_batch_handle='roll_over')

example/deep-embedded-clustering/dec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def cluster(self, X, y=None, update_interval=None):
122122

123123
def ce(label, pred):
124124
return np.sum(label*np.log(label/(pred+0.000001)))/label.shape[0]
125-
solver.set_metric(mx.metric.CustomMetric(ce))
125+
solver.set_metric(mx.gluon.metric.CustomMetric(ce))
126126

127127
label_buff = np.zeros((X.shape[0], self.num_centers))
128128
train_iter = mx.io.NDArrayIter({'data': X}, {'label': label_buff}, batch_size=batch_size,

example/distributed_training-horovod/gluon_mnist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def conv_nets():
104104
# Function to evaluate accuracy for a model
105105
def evaluate(model, data_iter, context):
106106
data_iter.reset()
107-
metric = mx.metric.Accuracy()
107+
metric = mx.gluon.metric.Accuracy()
108108
for _, batch in enumerate(data_iter):
109109
data = batch.data[0].as_in_context(context)
110110
label = batch.label[0].as_in_context(context)
@@ -149,7 +149,7 @@ def evaluate(model, data_iter, context):
149149

150150
# Create loss function and train metric
151151
loss_fn = gluon.loss.SoftmaxCrossEntropyLoss()
152-
metric = mx.metric.Accuracy()
152+
metric = mx.gluon.metric.Accuracy()
153153

154154
# Train model
155155
for epoch in range(args.epochs):

0 commit comments

Comments
 (0)