This commit is contained in:
2023-01-17 10:05:09 +00:00
parent b17baf157b
commit fd185d1b48
5 changed files with 222 additions and 91 deletions
+3 -3
View File
@@ -244,14 +244,14 @@ class ConvNeXtReverseBase2(nn.Module):
self.last = nn.Conv2d(
block_setting[-1].input_channels,
1,
kernel_size=7,
padding=3,
kernel_size=3,
padding='same',
).to(device)
# self.last = nn.Sequential(
# Permute([0, 2, 3, 1]),
# nn.Linear(in_features=block_setting[-1].input_channels, out_features=1, bias=True),
# Permute([0, 3, 1, 2]),
# )
# ).to(device)
for m in self.modules():
+47 -3
View File
@@ -16,7 +16,7 @@ class ViewEncoder(nn.Module):
self.flatten = nn.Flatten()
self.lin1 = nn.LazyLinear(features).to(device)
self.act1 = nn.GELU().to(device)
self.lin2 = nn.Linear(features, features * 15 * 20).to(device)
self.lin2 = nn.Linear(features, features).to(device)
self.act2 = nn.Tanh().to(device)
@@ -26,10 +26,51 @@ class ViewEncoder(nn.Module):
x = self.act1(x)
x = self.lin2(x)
x = self.act2(x)
x = x.view(x.shape[0],self.features,15,20)
x = torch.ones((x.shape[0], self.features, 15, 20), device=x.get_device()) * x[:,:,None,None]
return x
from torchvision.ops.misc import Conv2dNormActivation, Permute
class DumbReconstructor(nn.Module):
def __init__(self, view_features=128, device='cuda'):
super().__init__()
# self.model = torch.nn.Sequential(
# nn.ConvTranspose2d(768 + view_features, 128, 7, 4, 3),
# nn.BatchNorm2d(128),
# nn.ConvTranspose2d(128, 128, 7, 4, 3),
# nn.Conv2d(128, 64, 7, 1, 'same'),
# nn.BatchNorm2d(64),
# nn.ConvTranspose2d(64, 32, 7, 4, 3),
# nn.Conv2d(32, 1, 5, 1, 'same')
# ).to(device)
self.last = nn.Sequential(
nn.Linear(in_features=1024, out_features=480*640, bias=True),
).to(device)
def forward(self, input) -> torch.Tensor:
x = input
x = self.last(x).view((1,1,480,640))
return x
class DumbEncoder(nn.Module):
def __init__(self, view_features=128, device='cuda'):
super().__init__()
self.last = nn.Sequential(
nn.Flatten(),
nn.Linear(in_features=3*480*640, out_features=1024, bias=True),
).to(device)
def forward(self, input) -> torch.Tensor:
x = input
x = self.last(x)
return x, None
class DepthEstimation(nn.Module):
def __init__(self, view_features=128, device='cuda', use_skip=False):
super().__init__()
@@ -52,8 +93,10 @@ class DepthEstimation(nn.Module):
]
self.convnext = ConvNeXt(block_setting, device=device)
# self.convnext = DumbEncoder()
self.flatten = nn.Flatten()
self.decoder = ConvNeXt(block_setting_reverse, use_skip=use_skip, reversed=True, device=device)
# self.decoder = DumbReconstructor()
self.view_encoder = ViewEncoder(view_features)
@@ -63,6 +106,7 @@ class DepthEstimation(nn.Module):
x, features = self.convnext(image)
view_features = self.view_encoder(view)
# x = self.flatten(x)
x = self.decoder([torch.concat((x, view_features), axis=1),features])
x = self.decoder([torch.concat((x, view_features), axis=1), features])
# x = self.decoder(x)
return x