"其实一开始并没有想学深度学习"
bash
! pip install --upgrade pip
! pip install paddlex
! pip install --user --upgrade pyarrow==11.0.0
# 配置环境
train_list格式(test同理):图片路径+\t+标签
newLabels格式:标签
训练代码
python
import paddlex as pdx
from paddlex import transforms as T
train_transforms = T.Compose(
[T.RandomCrop(crop_size=224), T.RandomHorizontalFlip(), T.Normalize()])
eval_transforms = T.Compose([
T.ResizeByShort(short_size=256), T.CenterCrop(crop_size=224), T.Normalize()
])
# 定义数据集的transform
train_dataset = pdx.datasets.ImageNet(
data_dir='train',
file_list='train_list.txt',
label_list='newLabels.txt',
transforms=train_transforms,
shuffle=True)
eval_dataset = pdx.datasets.ImageNet(
data_dir='train',
file_list='val_list.txt',
label_list='newLabels.txt',
transforms=eval_transforms)
# 定义数据集
num_classes = len(train_dataset.labels)
model = pdx.cls.MobileNetV3_large_ssld(num_classes=num_classes)
model.train(num_epochs=6, # 训练轮次
train_dataset=train_dataset, #训练集
train_batch_size=32,# 训练batch
eval_dataset=eval_dataset, #测试集
lr_decay_epochs=[2, 4],# 学习率变化轮次
save_interval_epochs=2, # 保存模型轮次
learning_rate=0.00125,# 起始学习率
save_dir='output/mobilenetv3_large_ssld3',# 保存模型目录
use_vdl=True)
# 开始训练