1 Star 0 Fork 0

Zehebi / prismer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
utils.py 1.37 KB
一键复制 编辑 原始数据 按行查看 历史
Shikun Liu 提交于 2023-03-03 01:09 . First Commit
# Copyright (c) 2023, NVIDIA Corporation & Affiliates. All rights reserved.
#
# This work is made available under the Nvidia Source Code License-NC.
# To view a copy of this license, visit
# https://github.com/NVlabs/prismer/blob/main/LICENSE
import math
from pycocotools.coco import COCO
from pycocoevalcap.eval import COCOEvalCap
def cosine_lr_schedule(optimizer, epoch, max_epoch, init_lr, min_lr):
"""Decay the learning rate"""
lr = (init_lr - min_lr) * 0.5 * (1. + math.cos(math.pi * epoch / max_epoch)) + min_lr
for param_group in optimizer.param_groups:
param_group['lr'] = lr
def warmup_lr_schedule(optimizer, step, max_step, init_lr, max_lr):
"""Warmup the learning rate"""
lr = min(max_lr, init_lr + (max_lr - init_lr) * step / max_step)
for param_group in optimizer.param_groups:
param_group['lr'] = lr
def step_lr_schedule(optimizer, epoch, init_lr, min_lr, decay_rate):
"""Decay the learning rate"""
lr = max(min_lr, init_lr * (decay_rate ** epoch))
for param_group in optimizer.param_groups:
param_group['lr'] = lr
def coco_caption_eval(coco_gt_root, results_file):
coco = COCO(coco_gt_root)
coco_result = coco.loadRes(results_file)
coco_eval = COCOEvalCap(coco, coco_result)
coco_eval.evaluate()
for metric, score in coco_eval.eval.items():
print(f'{metric}: {score:.3f}')
return coco_eval
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/HangbinZheng/prismer.git
git@gitee.com:HangbinZheng/prismer.git
HangbinZheng
prismer
prismer
main

搜索帮助

344bd9b3 5694891 D2dac590 5694891