1 Star 0 Fork 0

ideaoverflow/CRAFT-Reimplementation

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
torchutil.py 857 Bytes
一键复制 编辑 原始数据 按行查看 历史
严海 提交于 2019-09-02 14:39 . first commit
# coding=utf-8
from collections import OrderedDict
import torch.nn as nn
import torch.nn.init as init
def copyStateDict(state_dict):
if list(state_dict.keys())[0].startswith("module"):
start_idx = 1
else:
start_idx = 0
new_state_dict = OrderedDict()
for k, v in state_dict.items():
name = ".".join(k.split(".")[start_idx:])
new_state_dict[name] = v
return new_state_dict
def init_weights(modules):
for m in modules:
if isinstance(m, nn.Conv2d):
init.xavier_uniform_(m.weight.data)
if m.bias is not None:
m.bias.data.zero_()
elif isinstance(m, nn.BatchNorm2d):
m.weight.data.fill_(1)
m.bias.data.zero_()
elif isinstance(m, nn.Linear):
m.weight.data.normal_(0, 0.01)
m.bias.data.zero_()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ideaoverflow/CRAFT-Reimplementation.git
git@gitee.com:ideaoverflow/CRAFT-Reimplementation.git
ideaoverflow
CRAFT-Reimplementation
CRAFT-Reimplementation
master

搜索帮助