<filename>train.py
from paddleseg.models import *
from paddleseg.datasets import Dataset
import paddle
from paddleseg.core import train
from paddleseg.models.losses import *
import paddleseg.transforms as T

model = OCRNet(num_classes = 4,
                backbone = HRNet_W48(), 
                pretrained = './model.pdparams',
                backbone_indices = [0]
            )

transforms = [
    T.RandomHorizontalFlip(),
    T.RandomDistort(
      brightness_range = 0.4,
      contrast_range = 0.4,
      saturation_range = 0.4,
    ),
    T.Normalize()
]
transforms_val = [
    T.Normalize()
]

# 构建训练集
train_dataset = Dataset(
    dataset_root='./',
    transforms=transforms,
    train_path = './train_path.txt',
    num_classes = 4,
    mode='train'
)
val_dataset = Dataset(
    dataset_root='./',
    transforms=transforms_val,
    val_path = './val_path.txt',
    num_classes = 4,
    mode='val'
)

base_lr = 0.0001
lr = paddle.optimizer.lr.PolynomialDecay(base_lr, power=0.9, decay_steps=300000, end_lr=0)

optimizer = paddle.optimizer.Momentum(lr, parameters=model.parameters(), momentum=0.9, weight_decay=4.0e-5)


losses = {}
losses['types'] = [MixedLoss([CrossEntropyLoss(), LovaszSoftmaxLoss()], [0.8, 0.2])] * 2
losses['coef'] = [0.8, 0.6]

train(
    model=model,
    train_dataset=train_dataset,
    val_dataset=val_dataset,
    optimizer=optimizer,
    save_dir='output',
    iters=30000,
    batch_size=16,
    save_interval=300,
    log_iters=10,
    losses=losses,
    use_vdl=True)
<filename>train.py
from paddleseg.models import *
from paddleseg.datasets import Dataset
import paddle
from paddleseg.core import train
from paddleseg.models.losses import *
import paddleseg.transforms as T

model = OCRNet(num_classes = 4,
                backbone = HRNet_W48(), 
                pretrained = './model.pdparams',
                backbone_indices = [0]
            )

transforms = [
    T.RandomHorizontalFlip(),
    T.RandomDistort(
      brightness_range = 0.4,
      contrast_range = 0.4,
      saturation_range = 0.4,
    ),
    T.Normalize()
]
transforms_val = [
    T.Normalize()
]

# 构建训练集
train_dataset = Dataset(
    dataset_root='./',
    transforms=transforms,
    train_path = './train_path.txt',
    num_classes = 4,
    mode='train'
)
val_dataset = Dataset(
    dataset_root='./',
    transforms=transforms_val,
    val_path = './val_path.txt',
    num_classes = 4,
    mode='val'
)

base_lr = 0.0001
lr = paddle.optimizer.lr.PolynomialDecay(base_lr, power=0.9, decay_steps=300000, end_lr=0)

optimizer = paddle.optimizer.Momentum(lr, parameters=model.parameters(), momentum=0.9, weight_decay=4.0e-5)


losses = {}
losses['types'] = [MixedLoss([CrossEntropyLoss(), LovaszSoftmaxLoss()], [0.8, 0.2])] * 2
losses['coef'] = [0.8, 0.6]

train(
    model=model,
    train_dataset=train_dataset,
    val_dataset=val_dataset,
    optimizer=optimizer,
    save_dir='output',
    iters=30000,
    batch_size=16,
    save_interval=300,
    log_iters=10,
    losses=losses,
    use_vdl=True)