change feature num to sync with nn-meter predict

This commit is contained in:
jiahangxu 2022-04-03 13:03:03 -04:00
Родитель 1e7e0a35b3
Коммит 9af03d48bc
5 изменённых файлов: 54 добавлений и 17 удалений

Просмотреть файл

@ -41,7 +41,7 @@ class PoolingSampler(BaseConfigSampler):
return sampling_pooling(sample_num)
def finegrained_config_sampling(self, configs, sample_num):
return finegrained_sampling_pooling(sample_num, fix_ks=3, fix_stride=1)
return finegrained_sampling_pooling(configs, sample_num)
class FCSampler(BaseConfigSampler):

Просмотреть файл

@ -94,7 +94,7 @@ def finegrained_sampling_pooling(cfgs, count):
'HW': cfg['HW'],
'CIN': cin,
'KERNEL_SIZE': cfg['KERNEL_SIZE'],
'STRIDES': cfg['STRIDES'],
'STRIDES': cfg['POOL_STRIDES'],
}
ncfgs.append(c)
return ncfgs

Просмотреть файл

@ -20,17 +20,17 @@ feature_for_kernel = {
"conv_hswish": ["HW", "CIN", "COUT", "KERNEL_SIZE", "STRIDES"],
"conv_block": ["HW", "CIN", "COUT", "KERNEL_SIZE", "STRIDES"],
"conv_bn_hswish": ["HW", "CIN", "COUT", "KERNEL_SIZE", "STRIDES"],
# dwconv
"dwconv_bn": ["HW", "CIN", "KERNEL_SIZE", "STRIDES"],
"dwconv_relu": ["HW", "CIN", "KERNEL_SIZE", "STRIDES"],
"dwconv_relu6": ["HW", "CIN", "KERNEL_SIZE", "STRIDES"],
"dwconv_bn_relu": ["HW", "CIN", "KERNEL_SIZE", "STRIDES"],
"dwconv_bn_relu6": ["HW", "CIN", "KERNEL_SIZE", "STRIDES"],
"dwconv_block": ["HW", "CIN", "KERNEL_SIZE", "STRIDES"],
"dwconv_bn_hswish": ["HW", "CIN", "KERNEL_SIZE", "STRIDES"],
# others
"maxpool_block": ["HW", "CIN", "KERNEL_SIZE", "POOL_STRIDES"],
"avgpool_block": ["HW", "CIN", "KERNEL_SIZE", "POOL_STRIDES"],
# dwconv ("COUT" will always be the same as "CIN")
"dwconv_bn": ["HW", "CIN", "COUT", "KERNEL_SIZE", "STRIDES"],
"dwconv_relu": ["HW", "CIN", "COUT", "KERNEL_SIZE", "STRIDES"],
"dwconv_relu6": ["HW", "CIN", "COUT", "KERNEL_SIZE", "STRIDES"],
"dwconv_bn_relu": ["HW", "CIN", "COUT", "KERNEL_SIZE", "STRIDES"],
"dwconv_bn_relu6": ["HW", "CIN", "COUT", "KERNEL_SIZE", "STRIDES"],
"dwconv_block": ["HW", "CIN", "COUT", "KERNEL_SIZE", "STRIDES"],
"dwconv_bn_hswish": ["HW", "CIN", "COUT", "KERNEL_SIZE", "STRIDES"],
# others ("COUT" will always be the same as "CIN")
"maxpool_block": ["HW", "CIN", "COUT", "KERNEL_SIZE", "POOL_STRIDES"],
"avgpool_block": ["HW", "CIN", "COUT", "KERNEL_SIZE", "POOL_STRIDES"],
"fc_block": ["CIN", "COUT"],
"concat_block": ["HW", "CIN1", "CIN2", "CIN3", "CIN4"],
"split_block": ["HW", "CIN"],
@ -41,8 +41,10 @@ feature_for_kernel = {
"bn_block": ["HW", "CIN"],
"hswish_block": ["HW", "CIN"],
"relu_block": ["HW", "CIN"],
"add_relu": ["HW", "CIN"],
"add_block": ["HW", "CIN"],
# In "add_relu" block and "add_block", the second feature "CIN" will always be the same as
# the third feature
"add_relu": ["HW", "CIN", "CIN"],
"add_block": ["HW", "CIN", "CIN"],
}
__user_config_folder__ = os.path.expanduser('~/.nn_meter/config')
@ -61,6 +63,8 @@ class BaseFeatureParser:
self.needed_config = feature_for_kernel[kernel_type]
def get_feature_by_config(self, config_dict):
if "COUT" not in config_dict and "COUT" in self.needed_config:
config_dict["COUT"] = config_dict["CIN"]
feature = [config_dict[data] for data in self.needed_config]
return feature
@ -72,6 +76,8 @@ class BaseFeatureParser:
class FlopsParamParser(BaseFeatureParser):
def get_feature_by_config(self, config_dict):
if "COUT" not in config_dict and "COUT" in self.needed_config:
config_dict["COUT"] = config_dict["CIN"]
feature = [config_dict[data] for data in self.needed_config]
from .utils import get_flops_params
flop, param = get_flops_params(self.kernel_type, config_dict)
@ -102,7 +108,8 @@ def get_feature_parser(kernel_type):
return BaseFeatureParser(kernel_type)
def get_data_by_profiled_results(kernel_type, feature_parser, cfgs_path, labs_path = None, save_path = None, predict_label = "latency"):
def get_data_by_profiled_results(kernel_type, feature_parser, cfgs_path, labs_path = None,
save_path = None, predict_label = "latency"):
''' return (features, latency)
kernel_type (str): type of kernel

Просмотреть файл

@ -378,6 +378,35 @@ __PREDICTOR_ZOO__ = {
"random_state": 10,
}
},
"add_block": {
"tflite_cpu": {
"max_depth": 50,
"n_estimators": 570,
"min_samples_leaf": 1,
"min_samples_split": 2,
"max_features": 3,
"oob_score": True,
"random_state": 10,
},
"tflite_gpu": {
"max_depth": 50,
"n_estimators": 570,
"min_samples_leaf": 1,
"min_samples_split": 2,
"max_features": 3,
"oob_score": True,
"random_state": 10,
},
"openvino_vpu": {
"max_depth": 50,
"n_estimators": 570,
"min_samples_leaf": 1,
"min_samples_split": 2,
"max_features": 3,
"oob_score": True,
"random_state": 10,
}
},
"split_block": {
"tflite_cpu": {
"max_depth": 50,

Просмотреть файл

@ -51,6 +51,7 @@ def get_predict_features(config):
inputh = item["inputh"]
if op in ["channelshuffle", "split"]:
[b, inputh, inputw, cin] = item["input_tensors"][0]
if "conv" in op:
flops, params = get_flops_params(op, inputh, cin, cout, ks, s)
features = [inputh, cin, cout, ks, s, flops / 2e6, params / 1e6]
@ -62,7 +63,7 @@ def get_predict_features(config):
elif "pool" in op and "global" not in op:
features = [inputh, cin, cout, ks, s]
elif "global-pool" in op or "global-avgpool" in op or "gap" in op:
inputh = 1
inputh = item["inputh"]
cin = item["cin"]
features = [inputh, cin]
elif "channelshuffle" in op: