lightly-ai/lightly

Clarification of x0 and x1 in the simsiam.py example

bryanbocao opened this issue · 2 comments

Thanks for the amazing SSL framework.

I have a few clarification questions regarding x0, x1:
Q1: Is x0 the original image (without being transformed) and x1 is the transformed one from the same image?
Q2: Are both x0 and x1 transformed but differently from the same image?

for epoch in range(10):
    total_loss = 0
    for batch in dataloader:
        x0, x1 = batch[0]
        x0 = x0.to(device)
        x1 = x1.to(device)
        z0, p0 = model(x0)
        z1, p1 = model(x1)
        loss = 0.5 * (criterion(z0, p1) + criterion(z1, p0))
        total_loss += loss.detach()
        loss.backward()
        optimizer.step()
        optimizer.zero_grad()
    avg_loss = total_loss / len(dataloader)
    print(f"epoch: {epoch:>02}, loss: {avg_loss:.5f}")

https://github.com/lightly-ai/lightly/blob/66ad1b40ebf3b53512703c774988211ce283211f/examples/pytorch/simsiam.py#L58C1-L58C1

Thanks!

Hi @bryanbocao, thanks for the question. For SimSiam transforms are used to generate two views of the original image. So x0 and x1 are different transformed views of the same image.

I'll close this for now, please reopen if you have further questions :)