The code is like:
# train_path = training_set
# initialize the Stratified K-Fold
folds = 10
skf = StratifiedKFold(n_splits=folds, shuffle=True, random_state=9)
# grab all the labels from the dataset
fnames = get_image_files(train_path)
random.shuffle(fnames)
labels = [parent_label(fn) for fn in fnames]
for train_idx, val_idx in skf.split(fnames, labels):
train_ds = DataBlock(
blocks=(ImageBlock, CategoryBlock),
get_items=get_image_files,
get_y=parent_label,
splitter=IndexSplitter(val_idx),
item_tfms=item_tfms,
batch_tfms=batch_tfms
)
dls = train_ds.dataloaders(train_path, bs=64)
# === create leaner ===
learn = vision_learner(dls, resnet34, pretrained=True, metrics=accuracy)
# using lr_find to find lr
s_lrs = learn.lr_find() # default lr_find(suggest_func=(valley))
s_lrs = s_lrs.valley
# === training ===
learn.fine_tune(epochs=10, base_lr=s_lrs)
_, val = learn.validate()
Is it possible to use the lr_find to set lr for learner’s fine_tune like this, when using Kfold CV so that in each fold, the lr will change due to ‘different’ training and validation set?