未验证 提交 54f014a6 编写于 作者: T Teng Xi 提交者: GitHub

Merge branch 'develop' into teng_ofa1

......@@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
sys.path.append("../")
import paddle
import unittest
import paddle.fluid as fluid
......
......@@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
sys.path.append("../")
import unittest
import paddle
from paddleslim.nas import SANAS
......
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
sys.path.append("../")
import paddle.fluid as fluid
import paddleslim.quant as quant
import unittest
......
......@@ -77,8 +77,7 @@ class TestQuantPostOnlyWeightCase1(unittest.TestCase):
fetch_list=outputs)
iter += 1
if iter % 100 == 0:
print(
'eval iter={}, avg loss {}, acc_top1 {}, acc_top5 {}'.
print('eval iter={}, avg loss {}, acc_top1 {}, acc_top5 {}'.
format(iter, cost, top1, top5))
result[0].append(cost)
result[1].append(top1)
......@@ -99,7 +98,7 @@ class TestQuantPostOnlyWeightCase1(unittest.TestCase):
params_filename='params')
quant_post_dynamic(
model_dir='./test_quant_post',
model_dir='./test_quant_post_dynamic',
save_model_dir='./test_quant_post_inference',
model_filename='model',
params_filename='params',
......
......@@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
sys.path.append("../")
import unittest
import paddle.fluid as fluid
from paddleslim.nas import RLNAS
......
......@@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
sys.path.append("../")
import os
import sys
import unittest
......@@ -19,6 +21,7 @@ from paddleslim.nas import SANAS
from paddleslim.analysis import flops
import numpy as np
def compute_op_num(program):
params = {}
ch_list = []
......@@ -29,14 +32,16 @@ def compute_op_num(program):
ch_list.append(int(param.shape[0]))
return params, ch_list
class TestSANAS(unittest.TestCase):
def setUp(self):
self.init_test_case()
port = np.random.randint(8337, 8773)
self.sanas = SANAS(configs=self.configs, server_addr=("", port), save_checkpoint=None)
self.sanas = SANAS(
configs=self.configs, server_addr=("", port), save_checkpoint=None)
def init_test_case(self):
self.configs=[('MobileNetV2BlockSpace', {'block_mask':[0]})]
self.configs = [('MobileNetV2BlockSpace', {'block_mask': [0]})]
self.filter_num = np.array([
3, 4, 8, 12, 16, 24, 32, 48, 64, 80, 96, 128, 144, 160, 192, 224,
256, 320, 384, 512
......@@ -53,7 +58,10 @@ class TestSANAS(unittest.TestCase):
conv_list, ch_pro = compute_op_num(program)
### assert conv number
self.assertTrue((repeat_num * 3) == len(conv_list), "the number of conv is NOT match, the number compute from token: {}, actual conv number: {}".format(repeat_num * 3, len(conv_list)))
self.assertTrue((repeat_num * 3) == len(
conv_list
), "the number of conv is NOT match, the number compute from token: {}, actual conv number: {}".
format(repeat_num * 3, len(conv_list)))
### assert number of channels
ch_token = []
......@@ -64,7 +72,10 @@ class TestSANAS(unittest.TestCase):
ch_token.append(filter_num)
init_ch_num = filter_num
self.assertTrue(str(ch_token) == str(ch_pro), "channel num is WRONG, channel num from token is {}, channel num come fom program is {}".format(str(ch_token), str(ch_pro)))
self.assertTrue(
str(ch_token) == str(ch_pro),
"channel num is WRONG, channel num from token is {}, channel num come fom program is {}".
format(str(ch_token), str(ch_pro)))
def test_all_function(self):
### unittest for next_archs
......@@ -73,7 +84,8 @@ class TestSANAS(unittest.TestCase):
token2arch_program = fluid.Program()
with fluid.program_guard(next_program, startup_program):
inputs = fluid.data(name='input', shape=[None, 3, 32, 32], dtype='float32')
inputs = fluid.data(
name='input', shape=[None, 3, 32, 32], dtype='float32')
archs = self.sanas.next_archs()
for arch in archs:
output = arch(inputs)
......@@ -85,8 +97,10 @@ class TestSANAS(unittest.TestCase):
### uniitest for tokens2arch
with fluid.program_guard(token2arch_program, startup_program):
inputs = fluid.data(name='input', shape=[None, 3, 32, 32], dtype='float32')
arch = self.sanas.tokens2arch(self.sanas.current_info()['current_tokens'])
inputs = fluid.data(
name='input', shape=[None, 3, 32, 32], dtype='float32')
arch = self.sanas.tokens2arch(self.sanas.current_info()[
'current_tokens'])
for arch in archs:
output = arch(inputs)
inputs = output
......@@ -94,7 +108,11 @@ class TestSANAS(unittest.TestCase):
### unittest for current_info
current_info = self.sanas.current_info()
self.assertTrue(isinstance(current_info, dict), "the type of current info must be dict, but now is {}".format(type(current_info)))
self.assertTrue(
isinstance(current_info, dict),
"the type of current info must be dict, but now is {}".format(
type(current_info)))
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册