Fine tuning sam
I have been trying to fine-tune sam model.I have an image of shape [B,3,1024,1024], masks of shape [B,256,256], and bounding box of shape [B,num_boxes,4]example:Screenshot 2023-07-04 at 7.49.40 PM2108×1068 257 KBI don’t knew where , I was going wrong but there is problem in the trainingnum_epochs = 100

device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)

model.train()
for epoch in range(num_epochs):
    epoch_losses = []
    for batch in tqdm(train_loader):
        # forward pass
        outputs = model(pixel_values=image.to(device),
                        input_boxes=boxes.to(device),
                        multimask_output=False)

        # compute loss
        predicted_masks = outputs.pred_masks.squeeze(1)
        ground_truth_masks = batch["ground_truth_mask"].float().to(device)
        loss = seg_loss(predicted_masks, ground_truth_masks.unsqueeze(1))

        # backward pass (compute gradients of parameters w.r.t. loss)
        optimizer.zero_grad()
        loss.backward()

        # optimize
        optimizer.step()
        epoch_losses.append(loss.item())

        # Release GPU memory
        torch.cuda.empty_cache()

    print(f'EPOCH: {epoch}')
    print(f'Mean loss: {mean(epoch_losses)}')And was encountering the following error in the training of the modelThe tutorial posted by@nielsrhas the tutorial about Sam in his repo.@nielsrhere is the error. How to get rid of this error?Screenshot 2023-07-04 at 8.27.51 PM2458×1220 501 KBScreenshot 2023-07-04 at 8.29.23 PM1920×915 182 KB
2023-07-04T15:01:28Z
should i have more gpu for this or ??what else I should do ,to work the code out?
2024-06-03T14:21:46Z
I’d recommend the following guide for tips and tricks regarding efficiently fine-tuning on a single GPU:Methods and tools for efficient training on a single GPU