import torch


def train_instance_discrimination(model, img, lbl, optimizer, criterion):
    # Zero the parameter's gradient
    optimizer.zero_grad()

    # Move data to GPU
    img, lbl = img.cuda(), lbl.cuda()

    # Get model prediction
    out = model(img, lbl)

    # Compute loss & metrics
    loss = criterion(out, lbl)

    # Compute parameter's gradient
    loss.backward()

    # Back-propagate and update parameters
    optimizer.step()

    # Optimization purposes
    loss_item = loss.item()
    return loss_item, loss_item


def val_instance_discrimination(model, img, lbl, criterion):
    model.eval()

    # Move data to GPU
    img, lbl = img.cuda(), lbl.cuda()

    with torch.no_grad():
        # Get model prediction
        out = model(img, lbl)

        # Compute loss & metrics
        loss = criterion(out, lbl)

    # Optimization purposes
    loss_item = loss.item()

    return loss_item, loss_item

762b544905bf1da6455e59ad6ef2a688f8002871
<mask token>

<mask token>


def val_instance_discrimination(model, img, lbl, criterion):
    model.eval()
    img, lbl = img.cuda(), lbl.cuda()
    with torch.no_grad():
        out = model(img, lbl)
        loss = criterion(out, lbl)
    loss_item = loss.item()
    return loss_item, loss_item

<mask token>


def train_instance_discrimination(model, img, lbl, optimizer, criterion):
    optimizer.zero_grad()
    img, lbl = img.cuda(), lbl.cuda()
    out = model(img, lbl)
    loss = criterion(out, lbl)
    loss.backward()
    optimizer.step()
    loss_item = loss.item()
    return loss_item, loss_item


def val_instance_discrimination(model, img, lbl, criterion):
    model.eval()
    img, lbl = img.cuda(), lbl.cuda()
    with torch.no_grad():
        out = model(img, lbl)
        loss = criterion(out, lbl)
    loss_item = loss.item()
    return loss_item, loss_item

import torch


def train_instance_discrimination(model, img, lbl, optimizer, criterion):
    optimizer.zero_grad()
    img, lbl = img.cuda(), lbl.cuda()
    out = model(img, lbl)
    loss = criterion(out, lbl)
    loss.backward()
    optimizer.step()
    loss_item = loss.item()
    return loss_item, loss_item


def val_instance_discrimination(model, img, lbl, criterion):
    model.eval()
    img, lbl = img.cuda(), lbl.cuda()
    with torch.no_grad():
        out = model(img, lbl)
        loss = criterion(out, lbl)
    loss_item = loss.item()
    return loss_item, loss_item

import torch


def train_instance_discrimination(model, img, lbl, optimizer, criterion):
    # Zero the parameter's gradient
    optimizer.zero_grad()

    # Move data to GPU
    img, lbl = img.cuda(), lbl.cuda()

    # Get model prediction
    out = model(img, lbl)

    # Compute loss & metrics
    loss = criterion(out, lbl)

    # Compute parameter's gradient
    loss.backward()

    # Back-propagate and update parameters
    optimizer.step()

    # Optimization purposes
    loss_item = loss.item()
    return loss_item, loss_item


def val_instance_discrimination(model, img, lbl, criterion):
    model.eval()

    # Move data to GPU
    img, lbl = img.cuda(), lbl.cuda()

    with torch.no_grad():
        # Get model prediction
        out = model(img, lbl)

        # Compute loss & metrics
        loss = criterion(out, lbl)

    # Optimization purposes
    loss_item = loss.item()

    return loss_item, loss_item
