resnet101 / base.py
modelExperience's picture
Upload 6 files
5b9ac22
Raw
History Blame
1.95 kB
import psutil
from pathlib import Path
import os
from utils import utils
from utils.utils import Singleton,read_yaml_file
# 读取模型yaml文件
class FileConfig(metaclass=Singleton):
def __init__(self):
# read model.yaml文件
cur_path = Path(os.path.abspath(__file__))
base_dir = cur_path.parent
self.model_config_path = base_dir / "model.yaml"
self.model_file = read_yaml_file(self.model_config_path.as_posix())
# self.model_path = base_dir / "resnet152-b121ed2d.pth"
# self.model_path = base_dir / "resnet18-5c106cde.pth"
# self.model_path = base_dir / "resnet34-333f7ec4.pth"
self.model_path = base_dir / "resnet101-5d3b4d8f.pth"
class BaseUI(object):
def __init__(self):
cur_path = Path(os.path.abspath(__file__))
cur_dir = cur_path.parent
self.file_init()
self.model_init()
def file_init(self):
# 初始化读取yaml文件
file_config_singleton = FileConfig()
self.mdoel_config_path = file_config_singleton.model_config_path
self.model_file = file_config_singleton.model_file
self.model_path = file_config_singleton.model_path
def model_init(self):
self.mdoel_name = self.model_file['model_name']
self.contrast_path = ('.' + str(self.model_file['contrast_path']))
self.transforms_Resize = [int(item) for item in self.model_file['transform']['Resize']]
self.transforms_Normalize_mean = [float(item) for item in self.model_file['transform']['Normalize']['mean']]
self.transforms_Normalize_std = [float(item) for item in self.model_file['transform']['Normalize']['std']]
self.transforms_centercrop_isExist = bool(self.model_file['transform']['centercrop']['isExist'])
if self.transforms_centercrop_isExist:
self.transforms_centercrop_value = int(self.model_file['transform']['centercrop']['value'])
baseui = BaseUI()