Thank you so much.
Please let me re-describe my question in another way. If we call trainer.test(model), I will test my model on my test set. I am not sure what are the functions it called, and where should I implement the related customized test.
For your advice, you have train and validation. I will attach the piece of code below. Please confirm if you are seeing test and validation calls the exact same functions.
def __init__(self,
encoder_model,
batch_size,
num_samples,
warmup_epochs=10,
lr=1e-4,
opt_weight_decay=1e-6,
loss_temperature=0.5,
**kwargs):
super().__init__()
self.encoder_model = encoder_model
self.save_hyperparameters()
self.entropy_loss = nn.CrossEntropyLoss()
self.nt_xent_loss = nt_xent_loss
self.encoder = self.init_encoder()
# h -> || -> z
self.projection = Projection(output_dim=7)
#nn.Linear(self.hidden_dim, 7, bias=False)
# Accuracy
self.acc = pl.metrics.Accuracy()
def training_step(self, batch, batch_idx):
loss, acc = self.shared_step(batch, batch_idx)
self.log('train_loss', loss, on_epoch=True)
self.log('train_acc', acc, on_epoch=True)
return loss
def validation_step(self, batch, batch_idx):
loss, acc = self.shared_step(batch, batch_idx)
self.log('avg_val_loss', loss)
self.log('avg_val_acc', acc)
return loss
def shared_step(self, batch, batch_idx):
(img1, img2), y = batch
# ENCODE
# encode -> representations
# (b, 3, 32, 32) -> (b, 2048, 2, 2)
h1 = self.encoder_model(img1)
#h2 = self.encoder(img2)
# the bolts resnets return a list of feature maps
if isinstance(h1, list):
h1 = h1[-1]
#h2 = h2[-1]
# PROJECT
# img -> E -> h -> || -> z
# (b, 2048, 2, 2) -> (b, 128)
z1 = self.projection(h1)
loss = self.entropy_loss(z1, y.cuda())
acc = self.acc(z1, y.cuda())
return loss, acc