1 Star 0 Fork 4

张钰奇/DeepLabV3PlusSemanticSegmentation

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
utils.py 1008 Bytes
一键复制 编辑 原始数据 按行查看 历史
xiaosha 提交于 5年前 . frist commit
from torchvision.transforms.functional import normalize
import torch.nn as nn
import numpy as np
import os
def denormalize(tensor, mean, std):
mean = np.array(mean)
std = np.array(std)
_mean = -mean/std
_std = 1/std
return normalize(tensor, _mean, _std)
class Denormalize(object):
def __init__(self, mean, std):
mean = np.array(mean)
std = np.array(std)
self._mean = -mean/std
self._std = 1/std
def __call__(self, tensor):
if isinstance(tensor, np.ndarray):
return (tensor - self._mean.reshape(-1,1,1)) / self._std.reshape(-1,1,1)
return normalize(tensor, self._mean, self._std)
def set_bn_momentum(model, momentum=0.1):
for m in model.modules():
if isinstance(m, nn.BatchNorm2d):
m.momentum = momentum
def fix_bn(model):
for m in model.modules():
if isinstance(m, nn.BatchNorm2d):
m.eval()
def mkdir(path):
if not os.path.exists(path):
os.mkdir(path)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xingyi247/deep-lab-v3-plus-semantic-segmentation.git
git@gitee.com:xingyi247/deep-lab-v3-plus-semantic-segmentation.git
xingyi247
deep-lab-v3-plus-semantic-segmentation
DeepLabV3PlusSemanticSegmentation
master

搜索帮助