加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
utils.py 850 Bytes
一键复制 编辑 原始数据 按行查看 历史
Colin_3f92 提交于 2019-12-20 19:19 . first commit
import os
import random
import numpy as np
#initialize the weighs of the network for Convolutional layers and batchnorm layers
def weights_init(m):
classname = m.__class__.__name__
if classname.find('Conv') != -1 and classname.find('Conv2d') == -1:
m.weight.data.normal_(0.0, 0.02)
elif classname.find('BatchNorm') != -1 and classname.find('BatchNorm2d') == -1:
m.weight.data.normal_(1.0, 0.02)
m.bias.data.fill_(0)
class AverageValueMeter(object):
"""Computes and stores the average and current value"""
def __init__(self):
self.reset()
def reset(self):
self.val = 0
self.avg = 0
self.sum = 0
self.count = 0.0
def update(self, val, n=1):
self.val = val
self.sum += val * n
self.count += n
self.avg = self.sum / self.count
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化