import numpy as np
from mindspore import Tensor, export, load_checkpoint
from mindvision.classification.models import resnet50
from mindvision.dataset import DownLoad

# 下载Resnet50的预训练模型
dl = DownLoad()
dl.download_url('https://download.mindspore.cn/vision/classification/resnet50_224.ckpt')

resnet = resnet50(1000)
load_checkpoint("resnet50_224.ckpt", net=resnet)

input_np = np.random.uniform(0.0, 1.0, size=[1, 3, 224, 224]).astype(np.float32)

# 导出文件resnet50_224.mindir到当前文件夹
export(resnet, Tensor(input_np), file_name='resnet50_224', file_format='MINDIR')



# 保存resnet50_224.onnx文件到当前目录下
export(resnet, Tensor(input_np), file_name='resnet50_224', file_format='ONNX')

