Last active
August 16, 2019 06:17
-
-
Save vinx13/6f1eb1f9e2c0a8786149ee881bfcd6aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import logging | |
import argparse | |
import os | |
import mxnet as mx | |
from mxnet import gluon | |
from mxnet.gluon.model_zoo import vision | |
import tvm | |
import tvm.relay as relay | |
import tvm.relay.expr as _expr | |
import tvm.relay.transform as _transform | |
from tvm.contrib import graph_runtime | |
from scipy import stats | |
import pickle | |
import multiprocessing as mp | |
# Two functions for reading data from record file or raw images | |
def get_val_data(args, | |
rec_val, | |
batch_size, | |
num_workers=4, | |
shuffle=False): | |
rec_val = os.path.expanduser(rec_val) | |
mean_rgb = [123.68, 116.779, 103.939] | |
std_rgb = [58.393, 57.12, 57.375] | |
def batch_fn(batch, ctx): | |
data = gluon.utils.split_and_load(batch.data[0], ctx_list=ctx, batch_axis=0) | |
label = gluon.utils.split_and_load(batch.label[0], ctx_list=ctx, batch_axis=0) | |
return data, label | |
img_size = 299 if args.model == 'inceptionv3' else 224 | |
val_data = mx.io.ImageRecordIter( | |
path_imgrec = rec_val, | |
preprocess_threads = num_workers, | |
shuffle = shuffle, | |
batch_size = batch_size, | |
resize = 256, | |
data_shape = (3, img_size, img_size), | |
mean_r = mean_rgb[0], | |
mean_g = mean_rgb[1], | |
mean_b = mean_rgb[2], | |
std_r = std_rgb[0], | |
std_g = std_rgb[1], | |
std_b = std_rgb[2], | |
) | |
return val_data, batch_fn | |
def calibration_dataset(): | |
val_data, batch_fn = get_val_data(args, args.rec_val, args.batch_size, shuffle=True) | |
val_data.reset() | |
for i, batch in enumerate(val_data): | |
if i*args.batch_size > args.calibration_samples: | |
break | |
data, label = batch_fn(batch, [mx.cpu(0)]) | |
yield {'data': data[0].asnumpy()} | |
def evaluate(args, graph, lib, params, ctx): | |
"""Evaluate on the validation set.""" | |
# setup dataset. | |
batch_size = args.batch_size | |
val_data, batch_fn = get_val_data(args, args.rec_val, batch_size) | |
# create runtime module | |
m = graph_runtime.create(graph, lib, ctx) | |
m.set_input(**params) | |
oshape = (batch_size, args.num_classes) | |
out_arr = tvm.nd.empty(oshape, "float32") | |
# setup evaluaiton metric | |
acc_top1 = mx.metric.Accuracy() | |
acc_top5 = mx.metric.TopKAccuracy(5) | |
val_data.reset() | |
acc_top1.reset() | |
acc_top5.reset() | |
# Execute | |
for i, batch in enumerate(val_data): | |
data, label = batch_fn(batch, [mx.cpu(0)]) | |
m.run(data=data[0].asnumpy()) | |
m.get_output(0, out_arr) | |
acc_top1.update(label, [mx.nd.array(out_arr.asnumpy())]) | |
acc_top5.update(label, [mx.nd.array(out_arr.asnumpy())]) | |
if args.log_interval and not (i + 1) % args.log_interval: | |
_, top1 = acc_top1.get() | |
_, top5 = acc_top5.get() | |
nsamples = (i + 1) * batch_size | |
logging.info('[%d samples] validation: acc-top1=%f acc-top5=%f', nsamples, top1, top5) | |
logging.info('[final] validation: acc-top1=%f acc-top5=%f', top1, top5) | |
with open(args.record_file, "a") as f: | |
f.write('{}, {} / {}\n'.format( | |
args.model, top1, top5)) | |
def calibrate_on_dataset(qgraph): | |
profile_graph = relay.quantize.collect_stats(qgraph) | |
with relay.build_config(opt_level=3): | |
graph, lib, params = relay.build(relay.Module.from_expr(profile_graph), target=args.target) | |
outputs = [] | |
m = graph_runtime.create(graph, lib, tvm.context(args.target, args.device_id)) | |
m.set_input(**params) | |
num_outputs = m.get_num_outputs() | |
outputs = [[] for i in range(num_outputs)] | |
for batch_id, batch in enumerate(calibration_dataset()): | |
print('batch {}..'.format(batch_id)) | |
m.set_input(**batch) | |
m.run() | |
for i in range(num_outputs): | |
output = m.get_output(i).asnumpy() | |
outputs[i].append(output) | |
for i in range(num_outputs): | |
outputs[i] = np.concatenate(outputs[i]).reshape(-1) | |
with mp.Pool() as pool: | |
scales = list(pool.map(relay.quantize.kl_divergence.kl_divergence_scale, outputs)) | |
return scales | |
def build_model(gluon_model, original): | |
"""Build with relay.""" | |
import tvm | |
from tvm import relay | |
from tvm.relay import quantize as qtz | |
img_size = 299 if args.model == 'inceptionv3' else 224 | |
data_shape = (args.batch_size, 3, img_size, img_size) | |
mod, params = relay.frontend.from_mxnet(gluon_model, {"data": data_shape}) | |
target = args.target | |
ctx = tvm.context(target, args.device_id) | |
if original: | |
# run original model | |
with relay.build_config(opt_level=3): | |
graph, lib, params = relay.build(net, target, params=params) | |
return graph, lib, params, ctx | |
skip_conv_layers = [0] | |
with relay.quantize.qconfig(store_lowbit_output=False, skip_conv_layers=skip_conv_layers): | |
from tvm.relay.quantize.quantize import _bind_params | |
graph = _bind_params(mod['main'], params) | |
mod = relay.Module.from_expr(graph) | |
optimize = _transform.Sequential([_transform.SimplifyInference(), | |
_transform.FoldConstant(), | |
_transform.FoldScaleAxis(), | |
_transform.CanonicalizeOps(), | |
_transform.FoldConstant()]) | |
with relay.build_config(opt_level=2): | |
mod = optimize(mod) | |
mod = relay.quantize.annotate()(mod) | |
cache_file = '{}_scales.pkl'.format(args.model) | |
if os.path.exists(cache_file): | |
with open(cache_file, 'rb') as f: | |
scales = pickle.load(f) | |
else: | |
scales = calibrate_on_dataset(mod['main']) | |
with open(cache_file, 'wb') as f: | |
pickle.dump(scales, f) | |
if args.eval_power2: | |
scales = list(map(lambda scale: 2**np.math.ceil(np.math.log(scale, 2)) if scale > 0 else 1.0, scales)) | |
weight_scales = 'power2' | |
else: | |
weight_scales = 'max' | |
mod['main'] = relay.quantize.calibrate(mod['main'], weight_scales=weight_scales, | |
scales=scales) | |
mod = relay.quantize.realize()(mod) | |
mod = relay.transform.FoldConstant()(mod) | |
graph, lib, params = relay.build(mod, target=args.target) | |
return graph, lib, params, ctx | |
def save_model(name, graph, lib, params): | |
with open(name + '.json', 'w') as f: | |
f.write(graph) | |
lib.export_library(name + '.so') | |
with open(name + '.bin', 'wb') as f: | |
f.write(relay.save_param_dict(params)) | |
def main(): | |
gluon_model = vision.get_model(args.model, pretrained=True) | |
graph, lib, params, ctx = build_model(gluon_model, args.original) | |
logging.info("Finish building model %s...", args.model) | |
evaluate(args, graph, lib, params, ctx) | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser(description="Evaluate ImageNet validation accuracy") | |
parser.add_argument("--rec-val", type=str, default="~/.mxnet/datasets/imagenet/rec/val.rec", | |
help="the validation data") | |
parser.add_argument("--num-classes", type=int, default=1000, | |
help="batch size") | |
parser.add_argument("--model", type=str, default="resnet50_v2", | |
help="Name of the model") | |
parser.add_argument("--log-interval", type=int, default=100, | |
help="log interval") | |
parser.add_argument("--batch-size", type=int, default=1, | |
help="batch size") | |
parser.add_argument("--target", type=str, default="cuda", | |
help="target option") | |
parser.add_argument("--original", action="store_true", | |
help='whether to use original graph') | |
parser.add_argument('--save_model', type=str, default=None) | |
parser.add_argument('--calibration_samples', type=int, default=100) | |
parser.add_argument('--device-id', type=int, default=0) | |
parser.add_argument('--eval-power2', action='store_true', | |
help='in this mode, scales are restricted to power-of-2 (weight: power2' \ | |
'scale, activation: round kld to power2)') | |
parser.add_argument('--record-file', type=str, default='record.csv', | |
help='file to save eval result') | |
args = parser.parse_args() | |
logging.basicConfig(level=logging.INFO) | |
logging.info(args) | |
main() |
mingwayzhang
commented
Aug 2, 2019
via email
Hi,
I used this script and got the following error. Did I miss anything?
[12:49:39] src/io/iter_image_recordio_2.cc:172: ImageRecordIOParser2:
/root/.mxnet/datasets/imagenet/rec/val.rec, use 4 threads for decoding..
Traceback (most recent call last):
File "./experiment/tuning_tools/quantization_eval.py", line 221, in
<module>
main()
File "./experiment/tuning_tools/quantization_eval.py", line 189, in main
graph, lib, params, ctx = build_model(gluon_model, args.original)
File "./experiment/tuning_tools/quantization_eval.py", line 159, in
build_model
scales = calibrate_on_dataset(mod['main'])
File "./experiment/tuning_tools/quantization_eval.py", line 109, in
calibrate_on_dataset
for batch_id, batch in enumerate(calibration_dataset()):
File "./experiment/tuning_tools/quantization_eval.py", line 52, in
calibration_dataset
val_data, batch_fn = get_val_data(args, args.rec_val, args.batch_size,
shuffle=True)
File "./experiment/tuning_tools/quantization_eval.py", line 46, in
get_val_data
std_b = std_rgb[2],
File "/usr/local/lib/python3.6/dist-packages/mxnet/io/io.py", line 960,
in creator
ctypes.byref(iter_handle)))
File "/usr/local/lib/python3.6/dist-packages/mxnet/base.py", line 253, in
check_call
raise MXNetError(py_str(_LIB.MXGetLastError()))
mxnet.base.MXNetError: [12:49:39] src/io/local_filesys.cc:104:
LocalFileSystem.ListDirectory /root/.mxnet/datasets/imagenet/rec error: No
such file or directory
Stack trace:
[bt] (0)
/usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x2ea8263)
[0x7f7d53a79263]
[bt] (1)
/usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x2eece91)
[0x7f7d53abde91]
[bt] (2)
/usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x2eee04b)
[0x7f7d53abf04b]
[bt] (3)
/usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x2eeec9f)
[0x7f7d53abfc9f]
[bt] (4)
/usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x2ea1f61)
[0x7f7d53a72f61]
[bt] (5)
/usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x2ea24fd)
[0x7f7d53a734fd]
[bt] (6)
/usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x26f1419)
[0x7f7d532c2419]
[bt] (7)
/usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x26f1bc3)
[0x7f7d532c2bc3]
[bt] (8)
/usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x26d91a9)
[0x7f7d532aa1a9]
Thanks.
…On Thu, Aug 1, 2019 at 9:35 PM Mingwei ***@***.***> wrote:
Hi,
Thanks for your email. Is this PR accepted in main branch? How can I get
the commits? Please let me know and it is a critical time for me to
evaluate TVM. Your help is much appreciated.
Thanks.
-Mingwei
On Thu, Aug 1, 2019 at 8:13 PM Wuwei Lin ***@***.***> wrote:
> it's in this PR apache/tvm#3538
>
> On Thu, Aug 1, 2019 at 6:01 PM mingwayzhang ***@***.***>
> wrote:
>
> > Hi,
> > I am wondering on which version of TVM is this script working on? I
> tried
> > to run it but errors out saying that "relay.quantize does not have
> > collect_stats" in Line 98. I did look at it, there is no such function
> at
> > all in recent TVM.
> >
> > So, if this one is obsolute, which one is the right script to evaluate
> the
> > quantize effect? Thanks
> >
> > —
> > You are receiving this because you authored the thread.
> > Reply to this email directly, view it on GitHub
> > <
> https://gist.github.com/6f1eb1f9e2c0a8786149ee881bfcd6aa?email_source=notifications&email_token=ABW4YW34OKA7SBMXNNLBBHDQCOBNNA5CNFSM4IIZNANKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFWLIO#gistcomment-2987655
> >,
> > or mute the thread
> > <
> https://github.com/notifications/unsubscribe-auth/ABW4YW532PGBIKC542GLGSTQCOBNNANCNFSM4IIZNANA
> >
> > .
> >
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <https://gist.github.com/6f1eb1f9e2c0a8786149ee881bfcd6aa?email_source=notifications&email_token=ACDKPKIWLEM4RHHZHOGLO2DQCOQ6DA5CNFSM4IIZNANKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFWLMU#gistcomment-2987722>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ACDKPKMMTYTMFQVZBRBSZLLQCOQ6DANCNFSM4IIZNANA>
> .
>
--
Mingwei Zhang
--
Mingwei Zhang
The PR has been accepted. You need to prepare the imagenet dataset in MXNet
record format (you can get instructions from the gluon website)
On Thu, Aug 1, 2019 at 9:51 PM mingwayzhang <[email protected]>
wrote:
… Hi,
I used this script and got the following error. Did I miss anything?
[12:49:39] src/io/iter_image_recordio_2.cc:172: ImageRecordIOParser2:
/root/.mxnet/datasets/imagenet/rec/val.rec, use 4 threads for decoding..
Traceback (most recent call last):
File "./experiment/tuning_tools/quantization_eval.py", line 221, in
<module>
main()
File "./experiment/tuning_tools/quantization_eval.py", line 189, in main
graph, lib, params, ctx = build_model(gluon_model, args.original)
File "./experiment/tuning_tools/quantization_eval.py", line 159, in
build_model
scales = calibrate_on_dataset(mod['main'])
File "./experiment/tuning_tools/quantization_eval.py", line 109, in
calibrate_on_dataset
for batch_id, batch in enumerate(calibration_dataset()):
File "./experiment/tuning_tools/quantization_eval.py", line 52, in
calibration_dataset
val_data, batch_fn = get_val_data(args, args.rec_val, args.batch_size,
shuffle=True)
File "./experiment/tuning_tools/quantization_eval.py", line 46, in
get_val_data
std_b = std_rgb[2],
File "/usr/local/lib/python3.6/dist-packages/mxnet/io/io.py", line 960,
in creator
ctypes.byref(iter_handle)))
File "/usr/local/lib/python3.6/dist-packages/mxnet/base.py", line 253, in
check_call
raise MXNetError(py_str(_LIB.MXGetLastError()))
mxnet.base.MXNetError: [12:49:39] src/io/local_filesys.cc:104:
LocalFileSystem.ListDirectory /root/.mxnet/datasets/imagenet/rec error: No
such file or directory
Stack trace:
[bt] (0)
/usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x2ea8263)
[0x7f7d53a79263]
[bt] (1)
/usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x2eece91)
[0x7f7d53abde91]
[bt] (2)
/usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x2eee04b)
[0x7f7d53abf04b]
[bt] (3)
/usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x2eeec9f)
[0x7f7d53abfc9f]
[bt] (4)
/usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x2ea1f61)
[0x7f7d53a72f61]
[bt] (5)
/usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x2ea24fd)
[0x7f7d53a734fd]
[bt] (6)
/usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x26f1419)
[0x7f7d532c2419]
[bt] (7)
/usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x26f1bc3)
[0x7f7d532c2bc3]
[bt] (8)
/usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x26d91a9)
[0x7f7d532aa1a9]
Thanks.
On Thu, Aug 1, 2019 at 9:35 PM Mingwei ***@***.***> wrote:
> Hi,
>
> Thanks for your email. Is this PR accepted in main branch? How can I get
> the commits? Please let me know and it is a critical time for me to
> evaluate TVM. Your help is much appreciated.
>
> Thanks.
> -Mingwei
>
> On Thu, Aug 1, 2019 at 8:13 PM Wuwei Lin ***@***.***>
wrote:
>
>> it's in this PR apache/tvm#3538
>>
>> On Thu, Aug 1, 2019 at 6:01 PM mingwayzhang ***@***.***>
>> wrote:
>>
>> > Hi,
>> > I am wondering on which version of TVM is this script working on? I
>> tried
>> > to run it but errors out saying that "relay.quantize does not have
>> > collect_stats" in Line 98. I did look at it, there is no such function
>> at
>> > all in recent TVM.
>> >
>> > So, if this one is obsolute, which one is the right script to evaluate
>> the
>> > quantize effect? Thanks
>> >
>> > —
>> > You are receiving this because you authored the thread.
>> > Reply to this email directly, view it on GitHub
>> > <
>>
https://gist.github.com/6f1eb1f9e2c0a8786149ee881bfcd6aa?email_source=notifications&email_token=ABW4YW34OKA7SBMXNNLBBHDQCOBNNA5CNFSM4IIZNANKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFWLIO#gistcomment-2987655
>> >,
>> > or mute the thread
>> > <
>>
https://github.com/notifications/unsubscribe-auth/ABW4YW532PGBIKC542GLGSTQCOBNNANCNFSM4IIZNANA
>> >
>> > .
>> >
>>
>> —
>> You are receiving this because you commented.
>> Reply to this email directly, view it on GitHub
>> <
https://gist.github.com/6f1eb1f9e2c0a8786149ee881bfcd6aa?email_source=notifications&email_token=ACDKPKIWLEM4RHHZHOGLO2DQCOQ6DA5CNFSM4IIZNANKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFWLMU#gistcomment-2987722
>,
>> or mute the thread
>> <
https://github.com/notifications/unsubscribe-auth/ACDKPKMMTYTMFQVZBRBSZLLQCOQ6DANCNFSM4IIZNANA
>
>> .
>>
>
>
> --
> Mingwei Zhang
>
--
Mingwei Zhang
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/6f1eb1f9e2c0a8786149ee881bfcd6aa?email_source=notifications&email_token=ABW4YW7MUPJTGLQ64W6F7MTQCO4NRA5CNFSM4IIZNANKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFWLP6#gistcomment-2987775>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABW4YW62LPQHD5LNUDMOMZ3QCO4NRANCNFSM4IIZNANA>
.
Congratulations! I will look into it.
…On Thu, Aug 1, 2019 at 10:31 PM Wuwei Lin ***@***.***> wrote:
The PR has been accepted. You need to prepare the imagenet dataset in MXNet
record format (you can get instructions from the gluon website)
On Thu, Aug 1, 2019 at 9:51 PM mingwayzhang ***@***.***>
wrote:
> Hi,
>
> I used this script and got the following error. Did I miss anything?
>
> [12:49:39] src/io/iter_image_recordio_2.cc:172: ImageRecordIOParser2:
> /root/.mxnet/datasets/imagenet/rec/val.rec, use 4 threads for decoding..
> Traceback (most recent call last):
> File "./experiment/tuning_tools/quantization_eval.py", line 221, in
> <module>
> main()
> File "./experiment/tuning_tools/quantization_eval.py", line 189, in main
> graph, lib, params, ctx = build_model(gluon_model, args.original)
> File "./experiment/tuning_tools/quantization_eval.py", line 159, in
> build_model
> scales = calibrate_on_dataset(mod['main'])
> File "./experiment/tuning_tools/quantization_eval.py", line 109, in
> calibrate_on_dataset
> for batch_id, batch in enumerate(calibration_dataset()):
> File "./experiment/tuning_tools/quantization_eval.py", line 52, in
> calibration_dataset
> val_data, batch_fn = get_val_data(args, args.rec_val, args.batch_size,
> shuffle=True)
> File "./experiment/tuning_tools/quantization_eval.py", line 46, in
> get_val_data
> std_b = std_rgb[2],
> File "/usr/local/lib/python3.6/dist-packages/mxnet/io/io.py", line 960,
> in creator
> ctypes.byref(iter_handle)))
> File "/usr/local/lib/python3.6/dist-packages/mxnet/base.py", line 253, in
> check_call
> raise MXNetError(py_str(_LIB.MXGetLastError()))
> mxnet.base.MXNetError: [12:49:39] src/io/local_filesys.cc:104:
> LocalFileSystem.ListDirectory /root/.mxnet/datasets/imagenet/rec error:
No
> such file or directory
> Stack trace:
> [bt] (0)
> /usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x2ea8263)
> [0x7f7d53a79263]
> [bt] (1)
> /usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x2eece91)
> [0x7f7d53abde91]
> [bt] (2)
> /usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x2eee04b)
> [0x7f7d53abf04b]
> [bt] (3)
> /usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x2eeec9f)
> [0x7f7d53abfc9f]
> [bt] (4)
> /usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x2ea1f61)
> [0x7f7d53a72f61]
> [bt] (5)
> /usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x2ea24fd)
> [0x7f7d53a734fd]
> [bt] (6)
> /usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x26f1419)
> [0x7f7d532c2419]
> [bt] (7)
> /usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x26f1bc3)
> [0x7f7d532c2bc3]
> [bt] (8)
> /usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x26d91a9)
> [0x7f7d532aa1a9]
>
> Thanks.
>
>
> On Thu, Aug 1, 2019 at 9:35 PM Mingwei ***@***.***> wrote:
>
> > Hi,
> >
> > Thanks for your email. Is this PR accepted in main branch? How can I
get
> > the commits? Please let me know and it is a critical time for me to
> > evaluate TVM. Your help is much appreciated.
> >
> > Thanks.
> > -Mingwei
> >
> > On Thu, Aug 1, 2019 at 8:13 PM Wuwei Lin ***@***.***>
> wrote:
> >
> >> it's in this PR apache/tvm#3538
> >>
> >> On Thu, Aug 1, 2019 at 6:01 PM mingwayzhang ***@***.***
>
> >> wrote:
> >>
> >> > Hi,
> >> > I am wondering on which version of TVM is this script working on? I
> >> tried
> >> > to run it but errors out saying that "relay.quantize does not have
> >> > collect_stats" in Line 98. I did look at it, there is no such
function
> >> at
> >> > all in recent TVM.
> >> >
> >> > So, if this one is obsolute, which one is the right script to
evaluate
> >> the
> >> > quantize effect? Thanks
> >> >
> >> > —
> >> > You are receiving this because you authored the thread.
> >> > Reply to this email directly, view it on GitHub
> >> > <
> >>
>
https://gist.github.com/6f1eb1f9e2c0a8786149ee881bfcd6aa?email_source=notifications&email_token=ABW4YW34OKA7SBMXNNLBBHDQCOBNNA5CNFSM4IIZNANKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFWLIO#gistcomment-2987655
> >> >,
> >> > or mute the thread
> >> > <
> >>
>
https://github.com/notifications/unsubscribe-auth/ABW4YW532PGBIKC542GLGSTQCOBNNANCNFSM4IIZNANA
> >> >
> >> > .
> >> >
> >>
> >> —
> >> You are receiving this because you commented.
> >> Reply to this email directly, view it on GitHub
> >> <
>
https://gist.github.com/6f1eb1f9e2c0a8786149ee881bfcd6aa?email_source=notifications&email_token=ACDKPKIWLEM4RHHZHOGLO2DQCOQ6DA5CNFSM4IIZNANKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFWLMU#gistcomment-2987722
> >,
> >> or mute the thread
> >> <
>
https://github.com/notifications/unsubscribe-auth/ACDKPKMMTYTMFQVZBRBSZLLQCOQ6DANCNFSM4IIZNANA
> >
> >> .
> >>
> >
> >
> > --
> > Mingwei Zhang
> >
>
>
> --
> Mingwei Zhang
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <
https://gist.github.com/6f1eb1f9e2c0a8786149ee881bfcd6aa?email_source=notifications&email_token=ABW4YW7MUPJTGLQ64W6F7MTQCO4NRA5CNFSM4IIZNANKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFWLP6#gistcomment-2987775
>,
> or mute the thread
> <
https://github.com/notifications/unsubscribe-auth/ABW4YW62LPQHD5LNUDMOMZ3QCO4NRANCNFSM4IIZNANA
>
> .
>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://gist.github.com/6f1eb1f9e2c0a8786149ee881bfcd6aa?email_source=notifications&email_token=ACDKPKNN37Z3RZ5F3OVE37LQCPBCDA5CNFSM4IIZNANKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFWLRM#gistcomment-2987798>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACDKPKOKK6OGLXOQFYGJDELQCPBCDANCNFSM4IIZNANA>
.
--
Mingwei Zhang
Hi Wuwei,
Which dataset in imagenet are you using? Could you share that with me?
Thanks.
…On Thu, Aug 1, 2019 at 10:48 PM Mingwei ***@***.***> wrote:
Congratulations! I will look into it.
On Thu, Aug 1, 2019 at 10:31 PM Wuwei Lin ***@***.***>
wrote:
> The PR has been accepted. You need to prepare the imagenet dataset in
> MXNet
> record format (you can get instructions from the gluon website)
>
> On Thu, Aug 1, 2019 at 9:51 PM mingwayzhang ***@***.***>
> wrote:
>
> > Hi,
> >
> > I used this script and got the following error. Did I miss anything?
> >
> > [12:49:39] src/io/iter_image_recordio_2.cc:172: ImageRecordIOParser2:
> > /root/.mxnet/datasets/imagenet/rec/val.rec, use 4 threads for decoding..
> > Traceback (most recent call last):
> > File "./experiment/tuning_tools/quantization_eval.py", line 221, in
> > <module>
> > main()
> > File "./experiment/tuning_tools/quantization_eval.py", line 189, in main
> > graph, lib, params, ctx = build_model(gluon_model, args.original)
> > File "./experiment/tuning_tools/quantization_eval.py", line 159, in
> > build_model
> > scales = calibrate_on_dataset(mod['main'])
> > File "./experiment/tuning_tools/quantization_eval.py", line 109, in
> > calibrate_on_dataset
> > for batch_id, batch in enumerate(calibration_dataset()):
> > File "./experiment/tuning_tools/quantization_eval.py", line 52, in
> > calibration_dataset
> > val_data, batch_fn = get_val_data(args, args.rec_val, args.batch_size,
> > shuffle=True)
> > File "./experiment/tuning_tools/quantization_eval.py", line 46, in
> > get_val_data
> > std_b = std_rgb[2],
> > File "/usr/local/lib/python3.6/dist-packages/mxnet/io/io.py", line 960,
> > in creator
> > ctypes.byref(iter_handle)))
> > File "/usr/local/lib/python3.6/dist-packages/mxnet/base.py", line 253,
> in
> > check_call
> > raise MXNetError(py_str(_LIB.MXGetLastError()))
> > mxnet.base.MXNetError: [12:49:39] src/io/local_filesys.cc:104:
> > LocalFileSystem.ListDirectory /root/.mxnet/datasets/imagenet/rec error:
> No
> > such file or directory
> > Stack trace:
> > [bt] (0)
> > /usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x2ea8263)
> > [0x7f7d53a79263]
> > [bt] (1)
> > /usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x2eece91)
> > [0x7f7d53abde91]
> > [bt] (2)
> > /usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x2eee04b)
> > [0x7f7d53abf04b]
> > [bt] (3)
> > /usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x2eeec9f)
> > [0x7f7d53abfc9f]
> > [bt] (4)
> > /usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x2ea1f61)
> > [0x7f7d53a72f61]
> > [bt] (5)
> > /usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x2ea24fd)
> > [0x7f7d53a734fd]
> > [bt] (6)
> > /usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x26f1419)
> > [0x7f7d532c2419]
> > [bt] (7)
> > /usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x26f1bc3)
> > [0x7f7d532c2bc3]
> > [bt] (8)
> > /usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x26d91a9)
> > [0x7f7d532aa1a9]
> >
> > Thanks.
> >
> >
> > On Thu, Aug 1, 2019 at 9:35 PM Mingwei ***@***.***> wrote:
> >
> > > Hi,
> > >
> > > Thanks for your email. Is this PR accepted in main branch? How can I
> get
> > > the commits? Please let me know and it is a critical time for me to
> > > evaluate TVM. Your help is much appreciated.
> > >
> > > Thanks.
> > > -Mingwei
> > >
> > > On Thu, Aug 1, 2019 at 8:13 PM Wuwei Lin ***@***.***>
> > wrote:
> > >
> > >> it's in this PR apache/tvm#3538
> > >>
> > >> On Thu, Aug 1, 2019 at 6:01 PM mingwayzhang <
> ***@***.***>
> > >> wrote:
> > >>
> > >> > Hi,
> > >> > I am wondering on which version of TVM is this script working on? I
> > >> tried
> > >> > to run it but errors out saying that "relay.quantize does not have
> > >> > collect_stats" in Line 98. I did look at it, there is no such
> function
> > >> at
> > >> > all in recent TVM.
> > >> >
> > >> > So, if this one is obsolute, which one is the right script to
> evaluate
> > >> the
> > >> > quantize effect? Thanks
> > >> >
> > >> > —
> > >> > You are receiving this because you authored the thread.
> > >> > Reply to this email directly, view it on GitHub
> > >> > <
> > >>
> >
> https://gist.github.com/6f1eb1f9e2c0a8786149ee881bfcd6aa?email_source=notifications&email_token=ABW4YW34OKA7SBMXNNLBBHDQCOBNNA5CNFSM4IIZNANKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFWLIO#gistcomment-2987655
> > >> >,
> > >> > or mute the thread
> > >> > <
> > >>
> >
> https://github.com/notifications/unsubscribe-auth/ABW4YW532PGBIKC542GLGSTQCOBNNANCNFSM4IIZNANA
> > >> >
> > >> > .
> > >> >
> > >>
> > >> —
> > >> You are receiving this because you commented.
> > >> Reply to this email directly, view it on GitHub
> > >> <
> >
> https://gist.github.com/6f1eb1f9e2c0a8786149ee881bfcd6aa?email_source=notifications&email_token=ACDKPKIWLEM4RHHZHOGLO2DQCOQ6DA5CNFSM4IIZNANKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFWLMU#gistcomment-2987722
> > >,
> > >> or mute the thread
> > >> <
> >
> https://github.com/notifications/unsubscribe-auth/ACDKPKMMTYTMFQVZBRBSZLLQCOQ6DANCNFSM4IIZNANA
> > >
> > >> .
> > >>
> > >
> > >
> > > --
> > > Mingwei Zhang
> > >
> >
> >
> > --
> > Mingwei Zhang
> >
> > —
> > You are receiving this because you authored the thread.
> > Reply to this email directly, view it on GitHub
> > <
> https://gist.github.com/6f1eb1f9e2c0a8786149ee881bfcd6aa?email_source=notifications&email_token=ABW4YW7MUPJTGLQ64W6F7MTQCO4NRA5CNFSM4IIZNANKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFWLP6#gistcomment-2987775
> >,
> > or mute the thread
> > <
> https://github.com/notifications/unsubscribe-auth/ABW4YW62LPQHD5LNUDMOMZ3QCO4NRANCNFSM4IIZNANA
> >
> > .
> >
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <https://gist.github.com/6f1eb1f9e2c0a8786149ee881bfcd6aa?email_source=notifications&email_token=ACDKPKNN37Z3RZ5F3OVE37LQCPBCDA5CNFSM4IIZNANKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFWLRM#gistcomment-2987798>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ACDKPKOKK6OGLXOQFYGJDELQCPBCDANCNFSM4IIZNANA>
> .
>
--
Mingwei Zhang
--
Mingwei Zhang
@mingwayzhang it's ILSVRC2012 val
I have registered an account in imagenet and downloaded the ILSVRC2012
validation data.
After that I used two commands using im2rec.py in the following
tutorial to generate metadata files:
https://gluon-cv.mxnet.io/build/examples_datasets/recordio.html#sphx-glr-download-build-examples-datasets-recordio-py
I am able to generate the lst, rec and idx file. I copied the rec file
to ~/.mxnet/datasets/imagenet/rec/val.rec and everything is working
fine.
I am able to launch your script. However, the accuracy is get lower
and lower (both top-1 accuracy and top-5).
INFO:root:[100 samples] validation: acc-top1=0.010000 acc-top5=0.010000
INFO:root:[200 samples] validation: acc-top1=0.005000 acc-top5=0.005000
INFO:root:[300 samples] validation: acc-top1=0.003333 acc-top5=0.003333
INFO:root:[400 samples] validation: acc-top1=0.002500 acc-top5=0.005000
INFO:root:[500 samples] validation: acc-top1=0.002000 acc-top5=0.004000
INFO:root:[600 samples] validation: acc-top1=0.001667 acc-top5=0.003333
INFO:root:[700 samples] validation: acc-top1=0.001429 acc-top5=0.002857
INFO:root:[800 samples] validation: acc-top1=0.001250 acc-top5=0.002500
INFO:root:[900 samples] validation: acc-top1=0.001111 acc-top5=0.003333
INFO:root:[1000 samples] validation: acc-top1=0.001000 acc-top5=0.004000
INFO:root:[1100 samples] validation: acc-top1=0.000909 acc-top5=0.003636
INFO:root:[1200 samples] validation: acc-top1=0.000833 acc-top5=0.004167
INFO:root:[1300 samples] validation: acc-top1=0.000769 acc-top5=0.004615
INFO:root:[1400 samples] validation: acc-top1=0.000714 acc-top5=0.004286
INFO:root:[1500 samples] validation: acc-top1=0.000667 acc-top5=0.004000
INFO:root:[1600 samples] validation: acc-top1=0.000625 acc-top5=0.003750
INFO:root:[1700 samples] validation: acc-top1=0.000588 acc-top5=0.004118
INFO:root:[1800 samples] validation: acc-top1=0.000556 acc-top5=0.003889
INFO:root:[1900 samples] validation: acc-top1=0.000526 acc-top5=0.003684
INFO:root:[2000 samples] validation: acc-top1=0.000500 acc-top5=0.003500
INFO:root:[2100 samples] validation: acc-top1=0.000476 acc-top5=0.003333
INFO:root:[2200 samples] validation: acc-top1=0.000455 acc-top5=0.003182
INFO:root:[2300 samples] validation: acc-top1=0.000435 acc-top5=0.003478
INFO:root:[2400 samples] validation: acc-top1=0.000417 acc-top5=0.003333
INFO:root:[2500 samples] validation: acc-top1=0.000400 acc-top5=0.003200
INFO:root:[2600 samples] validation: acc-top1=0.000769 acc-top5=0.003462
INFO:root:[2700 samples] validation: acc-top1=0.000741 acc-top5=0.004074
INFO:root:[2800 samples] validation: acc-top1=0.000714 acc-top5=0.004286
INFO:root:[2900 samples] validation: acc-top1=0.000690 acc-top5=0.004138
INFO:root:[3000 samples] validation: acc-top1=0.000667 acc-top5=0.004000
INFO:root:[3100 samples] validation: acc-top1=0.000645 acc-top5=0.004194
INFO:root:[3200 samples] validation: acc-top1=0.000625 acc-top5=0.004063
INFO:root:[3300 samples] validation: acc-top1=0.000909 acc-top5=0.004242
INFO:root:[3400 samples] validation: acc-top1=0.000882 acc-top5=0.004118
INFO:root:[3500 samples] validation: acc-top1=0.000857 acc-top5=0.004000
Is there anything I am missing? Please let me know.
Thank you
-Mingwei
…On Tue, Aug 13, 2019 at 10:16 PM Wuwei Lin ***@***.***> wrote:
@mingwayzhang it's ILSVRC2012 val
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
--
Mingwei Zhang
@mingwayzhang what model are you using?
Hi Wuwei,
I am actually using exactly the same script you gave me
(quantization_eval.py) with no additional parameters. So I should be using
resnet50_v2.
Thanks.
…On Wed, Aug 14, 2019 at 2:29 PM Wuwei Lin ***@***.***> wrote:
@mingwayzhang <https://github.com/mingwayzhang> what model are you using?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<https://gist.github.com/6f1eb1f9e2c0a8786149ee881bfcd6aa?email_source=notifications&email_token=ACDKPKMGHXN4GSTX3BDUO53QER2J3A5CNFSM4IIZNANKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFXBCM#gistcomment-2998822>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACDKPKKKXX6OGYWRQFM3JVTQER2J3ANCNFSM4IIZNANA>
.
--
Mingwei Zhang
Hi Wuwei,
I seriously tried the ILSVRC2012 valication data (6.3G). It seems that the
even the original model does not work. So could you tell me which data set
are you using?
If the dataset is correct, then could you tell me exactly the command that
you generate the val.rec?
Appreciate it.
Thanks
…On Wed, Aug 14, 2019 at 5:42 PM Mingwei ***@***.***> wrote:
Hi Wuwei,
I am actually using exactly the same script you gave me
(quantization_eval.py) with no additional parameters. So I should be using
resnet50_v2.
Thanks.
On Wed, Aug 14, 2019 at 2:29 PM Wuwei Lin ***@***.***>
wrote:
> @mingwayzhang <https://github.com/mingwayzhang> what model are you using?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://gist.github.com/6f1eb1f9e2c0a8786149ee881bfcd6aa?email_source=notifications&email_token=ACDKPKMGHXN4GSTX3BDUO53QER2J3A5CNFSM4IIZNANKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFXBCM#gistcomment-2998822>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ACDKPKKKXX6OGYWRQFM3JVTQER2J3ANCNFSM4IIZNANA>
> .
>
--
Mingwei Zhang
--
Mingwei Zhang
@mingwayzhang I have updated line 149 and it works fine locally. There are some accuracy issues after #3543 is merged. I'm working on it
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment