1 Star 0 Fork 0

秦敏杰/scanpath

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
fixation_duration.py 1.64 KB
一键复制 编辑 原始数据 按行查看 历史
sunwanjie 提交于 2020-10-20 16:28 . add code
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.distributions import Normal
from utils import WeightedGlobalMeanPool
class FixationDuration(nn.Module):
def __init__(self, feat_dim, roi_hidden_dim):
super(FixationDuration, self).__init__()
self.feat_dim = feat_dim
self.roi_hidden_dim = roi_hidden_dim
self.mu = nn.Sequential(
nn.Linear(self.feat_dim + self.roi_hidden_dim, 128),
nn.Tanh(),
nn.Linear(128, 32),
nn.Tanh(),
nn.Linear(32, 1)
)
self.mu[-1].bias.data.copy_(torch.rand_like(self.mu[-1].bias))
self.log_var = nn.Sequential(
nn.Linear(self.feat_dim + self.roi_hidden_dim, 128),
nn.Tanh(),
nn.Linear(128, 32),
nn.Tanh(),
nn.Linear(32, 1)
)
self.pool = WeightedGlobalMeanPool(keepdim=False)
def forward(self, feat, hidden, current_ROI):
spatial_size = feat.size()[2:]
with torch.no_grad():
current_roi = F.interpolate(current_ROI, size=spatial_size, mode='bilinear')
feat_vec = self.pool(feat, current_roi)
hidden_vec = self.pool(hidden, current_roi)
gaussian_input = torch.cat([feat_vec, hidden_vec], dim=-1)
mu = self.mu(gaussian_input)
mu = torch.clamp(mu, 0, 4)
sigma_squared = torch.exp(self.log_var(gaussian_input))
sigma = torch.sqrt(sigma_squared)
sigma = sigma.clamp(0.05, 0.1)
normal_distribution = Normal(mu, sigma)
sample = normal_distribution.rsample()
sample = sample.clamp(0, 4)
return sample
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/qin_minjie/scanpath.git
git@gitee.com:qin_minjie/scanpath.git
qin_minjie
scanpath
scanpath
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385