Hi, I have define a model like this:
In model.py
class Model(torch.nn.Module):
def init(self, args):
super(Model, self).init()
# Image Processing
self.conv1 = nn.Conv2d(3, 128, kernel_size=8, stride=4)
self.conv2 = nn.Conv2d(128, 64, kernel_size=4, stride=2)
self.conv3 = nn.Conv2d(64, 64, kernel_size=4, stride=2)
# Initializing weights
self.apply(weights_init)
self.train()
def forward(self, inputs):
"""
encoder is the Encoder part of a AutoEncoder
"""
encoder, x = inputs
#get the auto encoder representation
ae_v_emb = encoder.view(encoder.shape[0], -1)
# Get the image representation
x = F.relu(self.conv1(x))
x = F.relu(self.conv2(x))
x_image_rep = F.relu(self.conv3(x))
x_emb = x_image_rep.view(1, -1)
#Concat features
x_emb = torch.cat((x_emb, ae_v_emb), 1)
return x_emb
In train.py
I have defined training process like this:
from model import Model
model = Model()
auto_encoder_model = AutoEncoder()
optimizer = optim.SGD(model.parameters(), lr=args.lr)
…
#run Auto Encoder
encode = auto_encoder_model.encoder(image)
decode = auto_encoder_model.decoder(encoder)
features = model(encode, image)
…
optimizer.step()
I have passed an RGB image and an encoder of an Auto Encoder model into this model. My question is that I don’t define an optimizer for the Auto Encoder model, so can the encoder part of the auto encoder model be optimized through the optimizer of the main model (Model) ?
Thank you very much