MMPreTrain 代码课
视频链接: MMPretrain代码课_哔哩哔哩_bilibili
1. 安装pytorch
2. 安装mmpretrain
$ git clone https://github.com/open-mmlab/mmpretrain.git
$ cd mmpretrain
$ pip install openmin
$ min --help
$ min install -e ".[multimodal]"
3. 检测mmpretrain是否安装成功
import mmpretrain
mmpretrain.__version__
from mmpretrain import get_model, list_models, inference_model
list_models(task='Image Classfication', pattern='resnet18')
list_models(task='Image Caption', pattern='blip')
model = get_model('resnet18_8b16_cifar10')
inference_model('blip-base_3rdparty_caption', 'demo/cat-dog.png', show=True)
4. 查看图像
$ gthumb 图像路径
5. 配置参数: 模型,数据,优化器配置,运行参数配置
6. 微调
$ min train mmpretrain resnet18_finetune.py --work-dir=./exp
7. 测试
$ min test mmpretrain resnet18_finetune.py --checkpoint 模型权重路径
8. 测试分析
$ min test mmpretrain resnet18_finetune.py --checkpoint 模型权重路径 --out result.pkl
$ min run mmpretrain analyze_results resnet18_finetune.py result.pkl --out-dir analyze
$ min run mmpretrain confusion_matrix resnet18_finetune.py result.pkl --show --include-values
9. 在真实图片进行推理
from mmpretrain import ImageClassficationInference
inference = ImageClassficationInference('./resnet18_finetune.py', pretrained='模型权重路径')
inference('图像路径', show=True)