FastSAM icon indicating copy to clipboard operation
FastSAM copied to clipboard

Transfer Learning with FASTSAM

Open Sharpz7 opened this issue 2 years ago • 0 comments

Hey folks,

I am interested in applying Transfer Learning to FastSAM. I tried following the Training and Validation Code that was provided, but I have a few questions:

  • You don't specify FastSAM as the base model, why is this?
  • How can I "freeze" certain layers to improve results? Do you have suggestions for this?
  • How do I train text prompts and segmentations with the coco dataset? The code examples also do not do this I think?

Thanks. My long term goal is to make a "FastSAM" version of https://github.com/bowang-lab/MedSAM - I think that would be great.

Adam

======================

# Ultralytics YOLO 🚀, AGPL-3.0 license
# COCO8-seg dataset (first 8 images from COCO train2017) by Ultralytics
# Example usage: yolo train data=coco8-seg.yaml
# parent
# ├── ultralytics
# └── datasets
#     └── coco8-seg  ← downloads here (1 MB)


# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: ../datasets/coco8-seg  # dataset root dir
train: images/train  # train images (relative to 'path') 4 images
val: images/val  # val images (relative to 'path') 4 images
test:  # test images (optional)

# Classes
names:
  0: person
  1: bicycle
  2: car
  3: motorcycle
  4: airplane
  5: bus
  6: train
  7: truck
  8: boat
  9: traffic light
  10: fire hydrant
  11: stop sign
  12: parking meter
  13: bench
  14: bird
  15: cat
  16: dog
  17: horse
  18: sheep
  19: cow
  20: elephant
  21: bear
  22: zebra
  23: giraffe
  24: backpack
  25: umbrella
  26: handbag
  27: tie
  28: suitcase
  29: frisbee
  30: skis
  31: snowboard
  32: sports ball
  33: kite
  34: baseball bat
  35: baseball glove
  36: skateboard
  37: surfboard
  38: tennis racket
  39: bottle
  40: wine glass
  41: cup
  42: fork
  43: knife
  44: spoon
  45: bowl
  46: banana
  47: apple
  48: sandwich
  49: orange
  50: broccoli
  51: carrot
  52: hot dog
  53: pizza
  54: donut
  55: cake
  56: chair
  57: couch
  58: potted plant
  59: bed
  60: dining table
  61: toilet
  62: tv
  63: laptop
  64: mouse
  65: remote
  66: keyboard
  67: cell phone
  68: microwave
  69: oven
  70: toaster
  71: sink
  72: refrigerator
  73: book
  74: clock
  75: vase
  76: scissors
  77: teddy bear
  78: hair drier
  79: toothbrush


# Download script/URL (optional)
download: https://ultralytics.com/assets/coco8-seg.zip
from ultralytics import YOLO
import torch

DEVICE = torch.device(
    "cuda"
    if torch.cuda.is_available()
    else "mps"
    if torch.backends.mps.is_available()
    else "cpu"
)

model = YOLO(
    model="FastSAM.pt",
)
model.train(
    data="sa.yaml",
    epochs=100,
    batch=8,
    imgsz=1024,
    overlap_mask=False,
    save=True,
    save_period=5,
    device=DEVICE,
    project="fastsam",
    name="test",
    val=False,
)

Sharpz7 avatar Oct 11 '23 23:10 Sharpz7