forked from remotebiosensing/rppg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
DaeyeolKim
committed
Aug 2, 2021
1 parent
61fcd27
commit d0d2dd7
Showing
5 changed files
with
117 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import numpy as np | ||
import torch | ||
import torchvision.transforms as transforms | ||
from torch.utils.data import Dataset | ||
|
||
|
||
class MTTSDataset(Dataset): | ||
def __init__(self, appearance_data, motion_data, hr_target,rr_target): | ||
self.transform = transforms.Compose([transforms.ToTensor()]) | ||
self.a = appearance_data | ||
self.m = motion_data | ||
self.hr_label = hr_target.reshape(-1, 1) | ||
self.rr_label = rr_target.reshape(-1, 1) | ||
|
||
def __getitem__(self, index): | ||
if torch.is_tensor(index): | ||
index = index.tolist() | ||
|
||
appearance_data = torch.tensor(np.transpose(self.a[index], (2, 0, 1)), dtype=torch.float32) | ||
motion_data = torch.tensor(np.transpose(self.m[index], (2, 0, 1)), dtype=torch.float32) | ||
hr_target = torch.tensor(self.hr_label[index], dtype=torch.float32) | ||
rr_target = torch.tensor(self.rr_label[index], dtype=torch.float32) | ||
|
||
inputs = torch.stack([appearance_data,motion_data],dim=0) | ||
targets = torch.stack([hr_target,rr_target],dim=0) | ||
|
||
if torch.cuda.is_available(): | ||
inputs = inputs.to('cuda') | ||
targets = targets.to('cuda') | ||
|
||
return inputs, targets | ||
|
||
def __len__(self): | ||
return len(self.hr_label) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import torch | ||
|
||
from nets.models.sub_models.AppearanceModel import AppearanceModel_2D | ||
from nets.models.sub_models.LinearModel import LinearModel | ||
from nets.models.sub_models.MotionModel import MotionModel_TS | ||
|
||
|
||
class MTTS(torch.nn.Module): | ||
def __init__(self): | ||
super().__init__() | ||
self.in_channels = 3 | ||
self.out_channels = 32 | ||
self.kernel_size = 3 | ||
self.attention_mask1 = None | ||
self.attention_mask2 = None | ||
|
||
self.appearance_model = AppearanceModel_2D(in_channels=self.in_channels, out_channels=self.out_channels, | ||
kernel_size=self.kernel_size) | ||
self.motion_model = MotionModel_TS(in_channels=self.in_channels, out_channels=self.out_channels, | ||
kernel_size=self.kernel_size) | ||
|
||
self.hr_linear_model = LinearModel() | ||
self.rr_linear_model = LinearModel() | ||
|
||
def forward(self, inputs): | ||
""" | ||
:param inputs: | ||
inputs[0] : appearance_input | ||
inputs[1] : motion_input | ||
:return: | ||
original 2d model | ||
""" | ||
inputs = torch.chunk(inputs,2,dim=1) | ||
self.attention_mask1, self.attention_mask2 = self.appearance_model(torch.squeeze(inputs[0],1)) | ||
motion_output = self.motion_model(torch.squeeze(inputs[1],1), self.attention_mask1, self.attention_mask2) | ||
hr_out = self.linear_model(motion_output) | ||
rr_out = self.linear_model(motion_output) | ||
|
||
return [hr_out,rr_out] | ||
|
||
def get_attention_mask(self): | ||
return self.attention_mask1, self.attention_mask2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters