kadirnar / segment-anything-video

MetaSeg: Packaged version of the Segment Anything repository
Apache License 2.0
946 stars 67 forks source link

installed metaseg but it doesn't download models #88

Closed DiamondGlassDrill closed 1 year ago

DiamondGlassDrill commented 1 year ago

Tried to use metaseg in image and video project but couldn't do anything as it claimed that it doesn't know a model_type: self.segmentor = SegAutoMaskPredictor(model_type="vit_l", points_per_side=16, points_per_batch=64) TypeError: init() got an unexpected keyword argument 'model_type'

Code: import cv2 from PyQt6 import QtCore, QtGui, QtWidgets from led_grid import LedGrid from metaseg import SegAutoMaskPredictor

class HandTracker(QtCore.QObject): def init(self, grid): super().init() self.grid = grid self.cap = cv2.VideoCapture(0) self.segmentor = SegAutoMaskPredictor(model_type="vit_l", points_per_side=16, points_per_batch=64)

def load_video(self, filepath):
    self.cap = cv2.VideoCapture(filepath)

def step(self):
    success, image = self.cap.read()
    if not success:
        print("Ignoring empty camera frame.")
        return

    image = cv2.cvtColor(cv2.flip(image, 1), cv2.COLOR_BGR2RGB)
    results = self.segmentor.image_predict(
        source=image,
        min_area=1000,
        show=False,
        save=False,
    )
DiamondGlassDrill commented 1 year ago

I tried also to look where I can add models in e.g. site_packages metaseg but couldn't find where to add it?

onuralpszr commented 1 year ago

Hello

You should provide model type in image_predict and it will download the file automatically and start do detection afterwards

SegAutoMaskPredictor <-- this init doesn't take model_type so it is a syntax error.

If you check here https://github.com/kadirnar/segment-anything-video/blob/main/examples/image_cv_segautomask.py#L12

You can see that we use model_type at "image_predict"

DiamondGlassDrill commented 1 year ago

Will check it tomorrow. Makes total sense, and the advice never code when tired, just to make the code base ready :). Thanks for the support.