第二阶段赛题背景: 为什么关注acc而非ranking? 在很多场景,我们需要搜索到在特定硬件上精度不低于特定指标的最优的模型结构,只预测相对排序无法保证搜索结构可以满足精度的约束条件。 few shot背景: predictor based模型结构搜索, 需要采样足够多的模型结构来训练预测器,将模型结构训到较高的指标需要加很多trick并且需要训练非常久,从而限制采样子网络的数量。代理任务可以快速获得模型的精度,但是代理任务的精度分布与加入trick并且训练更久的精度分布之间会有diff。第二阶段的目标就是,基于第一阶段的代理任务采样的模型结构与模型精度之间的关联性,在只采样非常少量模型结构在非代理任务(加入trick并且训练更久)上的精度情况下,就可以准确的预测任意模型结构在非代理任务上的精度。
本demo基于paddleslim自研NAS算法[GP-NAS:Gaussian Process based Neural Architecture Search](https://openaccess.thecvf.com/content_CVPR_2020/papers/Li_GP-NAS_Gaussian_Process_Based_Neural_Architecture_Search_CVPR_2020_paper.pdf)(CVPR2020)
# Copyright (c) 2021 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.
importnumpyasnp
importcopy
__all__=["GPNAS"]
classGPNAS(object):
"""
GPNAS(Gaussian Process based Neural Architecture Search) is a neural architecture search algorithm.
We model the correlation between architectue and performance from a Bayesian perspective. Specifically, by introducing a novel Gaussian Process based
NAS (GP-NAS) method, the correlations are modeled by the kernel function and mean function. The kernel function is also learnable to enable adaptive modeling for complex
correlations in different search spaces. Furthermore, by in-corporating a mutual information based sampling method, we can theoretically ensure the high-performance
architecture with only a small set of samples. After addressing these problems, training GP-NAS once enables direct performance prediction of any architecture in different
scenarios and may obtain efficient networks for different deployment platforms.
"""
def__init__(self,c_flag=2,m_flag=2):
self.hp_mat=0.0000001
self.hp_cov=0.01
self.cov_w=None
self.w=None
self.c_flag=c_flag
self.m_flag=m_flag
def_get_corelation(self,mat1,mat2):
"""
give two typical kernel function
Auto kernel hyperparameters estimation to be updated