Skip to content

Commit 19365c6

Browse files
authored
Merge pull request #63 from foss-for-synopsys-dwc-arc-processors/cifar10_tut
Cifar10 tutorial-like scripts
2 parents 3d0ca8e + dfec06c commit 19365c6

File tree

5 files changed

+885
-0
lines changed

5 files changed

+885
-0
lines changed
Binary file not shown.
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
name: "CIFAR10_quick"
2+
layer {
3+
name: "data"
4+
type: "Input"
5+
top: "data"
6+
input_param { shape: { dim: 1 dim: 3 dim: 32 dim: 32 } }
7+
}
8+
layer {
9+
name: "conv1"
10+
type: "Convolution"
11+
bottom: "data"
12+
top: "conv1"
13+
param {
14+
lr_mult: 1
15+
}
16+
param {
17+
lr_mult: 2
18+
}
19+
convolution_param {
20+
num_output: 32
21+
pad: 2
22+
kernel_size: 5
23+
stride: 1
24+
}
25+
}
26+
layer {
27+
name: "pool1"
28+
type: "Pooling"
29+
bottom: "conv1"
30+
top: "pool1"
31+
pooling_param {
32+
pool: MAX
33+
kernel_size: 3
34+
stride: 2
35+
}
36+
}
37+
layer {
38+
name: "relu1"
39+
type: "ReLU"
40+
bottom: "pool1"
41+
top: "pool1"
42+
}
43+
layer {
44+
name: "conv2"
45+
type: "Convolution"
46+
bottom: "pool1"
47+
top: "conv2"
48+
param {
49+
lr_mult: 1
50+
}
51+
param {
52+
lr_mult: 2
53+
}
54+
convolution_param {
55+
num_output: 16
56+
pad: 2
57+
kernel_size: 5
58+
stride: 1
59+
}
60+
}
61+
layer {
62+
name: "relu2"
63+
type: "ReLU"
64+
bottom: "conv2"
65+
top: "conv2"
66+
}
67+
layer {
68+
name: "pool2"
69+
type: "Pooling"
70+
bottom: "conv2"
71+
top: "pool2"
72+
pooling_param {
73+
pool: AVE
74+
kernel_size: 3
75+
stride: 2
76+
}
77+
}
78+
layer {
79+
name: "conv3"
80+
type: "Convolution"
81+
bottom: "pool2"
82+
top: "conv3"
83+
param {
84+
lr_mult: 1
85+
}
86+
param {
87+
lr_mult: 2
88+
}
89+
convolution_param {
90+
num_output: 32
91+
pad: 2
92+
kernel_size: 5
93+
stride: 1
94+
}
95+
}
96+
layer {
97+
name: "relu3"
98+
type: "ReLU"
99+
bottom: "conv3"
100+
top: "conv3"
101+
}
102+
layer {
103+
name: "pool3"
104+
type: "Pooling"
105+
bottom: "conv3"
106+
top: "pool3"
107+
pooling_param {
108+
pool: AVE
109+
kernel_size: 3
110+
stride: 2
111+
}
112+
}
113+
layer {
114+
name: "ip1"
115+
type: "InnerProduct"
116+
bottom: "pool3"
117+
top: "ip1"
118+
param {
119+
lr_mult: 1
120+
}
121+
param {
122+
lr_mult: 2
123+
}
124+
inner_product_param {
125+
num_output: 10
126+
}
127+
}
128+
layer {
129+
name: "prob"
130+
type: "Softmax"
131+
bottom: "ip1"
132+
top: "prob"
133+
}
134+
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Copyright 2019, Synopsys, Inc.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-3-Clause license found in
5+
# the LICENSE file in the root directory of this source tree.
6+
#
7+
"""
8+
embarc Machine Learning Inference Library (embarc MLI):
9+
Model Deployment tutorial for Caffe and CIFAR-10: Launching script
10+
"""
11+
12+
import argparse
13+
from deployment_steps import *
14+
15+
16+
def main(argn):
17+
# Go through the model deployment tutorial for Caffe and CIFAR-10 step-by-step
18+
print('MLI Deployment tutorial script.')
19+
print('Used parameters:')
20+
for param, val in vars(argn).items():
21+
print('\t{}: {}'.format(param, val))
22+
print("\n")
23+
24+
print("Step 1: Instrument the input model.")
25+
classifier, layers, ir_tensors = instrument_model_step(argn.prototext, argn.model)
26+
print("Done\n")
27+
28+
print("Step 2: Collect data statistic for each layer.")
29+
collect_inference_statistic_step(classifier, argn.lmdb_data_dir, ir_tensors, 128.0, 1.0 / 128.0)
30+
print("Done\n")
31+
32+
print("Step 3: Define Qm.n data format.")
33+
define_qmn_step(layers, argn.kernel_type)
34+
print("Done\n")
35+
36+
print("Step 4: Quantize and output weights.")
37+
quantize_and_output_step(layers, argn.kernel_type, argn.output_prefix, argn.wrap_coefficients)
38+
print("Done\n")
39+
40+
# Next step should be done manually using generated files
41+
# write_code_for_me(...)
42+
43+
44+
if __name__ == '__main__':
45+
parser = argparse.ArgumentParser(description="CIFAR-10 for Caffe Deployment Tutorial Script ",
46+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
47+
parser.add_argument(
48+
'--lmdb_data_dir',
49+
type=str,
50+
default='cifar10_train_lmdb',
51+
help='Path to CIFAR-10 subset in LMDB format (created by caffe cifar-10 example specific tool)')
52+
parser.add_argument(
53+
'--model',
54+
type=str,
55+
default='cifar10_small.caffemodel.h5',
56+
help='CIFAR-10 caffemodl file')
57+
parser.add_argument(
58+
'--prototext',
59+
type=str,
60+
default='cifar10_small.prototxt',
61+
help='CIFAR-10 test prototext file')
62+
parser.add_argument(
63+
'--output_prefix',
64+
type=str,
65+
default='cifar10_small',
66+
help='Prefix for output files including *.inc(coefficients) *.c (tensors) *.h (declarations)')
67+
parser.add_argument(
68+
'--kernel_type',
69+
type=str,
70+
default='fx8',
71+
choices=['fx8', 'fx16', 'fx8w16d'],
72+
help='')
73+
parser.add_argument(
74+
'--wrap_coefficients',
75+
action='store_true',
76+
help='Wrap float values into macro for compile-time quantization purpose')
77+
78+
flags, unparsed = parser.parse_known_args()
79+
main(flags)

0 commit comments

Comments
 (0)