/
models.py
34 lines (24 loc) · 1.35 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
## TODO: define the convolutional neural network architecture
import torch
import torch.nn as nn
import torch.nn.functional as F
# can use the below import should you choose to initialize the weights of your Net
import torch.nn.init as I
from torchvision import models
from collections import OrderedDict
class resnet18(nn.Module):
def __init__(self):
super(resnet18, self).__init__()
self.resnet18 = models.resnet18(pretrained=True)
self.resnet18.conv1 = nn.Conv2d(1, 64, kernel_size=(9, 9), stride=(2, 2), padding=(3, 3), bias=False)
n_inputs = self.resnet18.fc.in_features
self.resnet18.fc = nn.Linear(n_inputs, 136)
def forward(self, x):
x = self.resnet18(x)
return x
## TODO: Define all the layers of this CNN, the only requirements are:
## 1. This network takes in a square (same width and height), grayscale image as input
## 2. It ends with a linear layer that represents the keypoints
## it's suggested that you make this last layer output 136 values, 2 for each of the 68 keypoint (x, y) pairs
# As an example, you've been given a convolutional layer, which you may (but don't have to) change:
# 1 input image channel (grayscale), 32 output channels/feature maps, 5x5 square convolution kernel