in docker_images/mindspore/app/pipelines/image_classification.py [0:0]
def load_model_config_from_hf(model_id):
repo_path = snapshot_download(model_id)
config_json_file = os.path.join(repo_path, "config.json")
if not os.path.exists(config_json_file):
raise EnvironmentError(
f"The path of the config.json file {config_json_file} doesn't exist!"
)
config = load_config(config_json_file)
architecture = config.get("architecture")
if architecture not in ALLOWED_MODEL:
raise EnvironmentError(f"Currently doesn't supports {model} model!")
net_func = ALLOWED_MODEL.get(architecture)
class_num = config.get("num_classes")
net = net_func(class_num=class_num, is_training=False)
ms_model = model.Model(net)
model_file = os.path.join(repo_path, "mindspore_model.ckpt")
if not os.path.exists(model_file):
raise EnvironmentError(
f"The path of the model file {model_file} doesn't exist!"
)
ms_model.load_checkpoint(model_file)
return ms_model, config