【发布时间】:2020-12-12 00:42:34
【问题描述】:
我正在尝试创建一个具有 L(来自 Lab)格式的图像并输出 ab 尺寸的神经网络。我能够毫无问题地通过 L 尺寸,但我无法弄清楚如何输出 ab 尺寸。输出应该是形状 1x2xHxW,其中 H 和 W 是输入图像的高度和宽度。到目前为止,这是我的网络:
class Model(nn.Module):
def __init__(self):
super(Model, self).__init__()
# Get the resnet18 model from torchvision.model library
self.model = models.resnet18(pretrained=True)
self.model.conv1 = nn.Conv2d(1, 64, kernel_size=7, stride=2, padding=3, bias=False)
# Replace fully connected layer of our model to a 2048 feature vector output
self.model.classifier = nn.Sequential()
# Add custom classifier layers
self.fc1 = nn.Linear(1000, 1024)
self.Dropout1 = nn.Dropout()
self.PRelU1 = nn.PReLU()
self.fc2 = nn.Linear(1024, 512)
self.Dropout2 = nn.Dropout()
self.PRelU2 = nn.PReLU()
self.fc3 = nn.Linear(512, 256)
self.Dropout3 = nn.Dropout()
self.PRelU3 = nn.PReLU()
self.fc4 = nn.Linear(256, 313)
# self.PRelU3 = nn.PReLU()
self.softmax = nn.Softmax(dim=1)
self.model_out = nn.Conv2d(313, 2, kernel_size=1, padding=0, dilation=1, stride=1, bias=False)
self.upsample4 = nn.Upsample(scale_factor=4, mode='bilinear')
def forward(self, x):
# x is our input data
x = self.model(x)
x = self.Dropout1(self.PRelU1(self.fc1(x)))
x = self.Dropout2(self.PRelU2(self.fc2(x)))
x = self.Dropout3(self.PRelU3(self.fc3(x)))
x = self.softmax(self.fc4(x))
return x
【问题讨论】:
-
拍摄图像,执行您的功能并生成与您在其上执行的功能相同的图像,这对于
autoencoder来说是完美的任务。参考这个:jeremyjordan.me/autoencoders -
U-net style architectures 可能是最流行的架构类型。基本上类似于自动编码器或编码器/解码器网络,但在编码器和解码器之间有跳跃连接。
标签: python machine-learning pytorch conv-neural-network