Fehler "Name 'Clip' ist nicht definiert", wenn Clip mit FastSAM verwendet wirdPython

Python-Programme
Guest
 Fehler "Name 'Clip' ist nicht definiert", wenn Clip mit FastSAM verwendet wird

Post by Guest »

Ich verfolge einige Tutorials und habe den folgenden Code in Google Colab: < /p>

Code: Select all

!pip install matplotlib==3.7.3
!git clone https://github.com/CASIA-IVA-Lab/FastSAM.git
!pip -q install -r FastSAM/requirements.txt

# install CLIP ----------
#!pip -q install git+https://github.com/openai/CLIP.git
!pip -q install openai-clip

!wget -P {HOME}/FastSAM/weights -q https://huggingface.co/spaces/An-
619/FastSAM/resolve/main/weights/FastSAM.pt

FAST_SAM_CHECKPOINT_PATH = f"{HOME}/FastSAM/weights/FastSAM.pt"
DOGImage_PATH = f"{HOME}/FastSAM/images/dogs.jpg"

%cd {HOME}/FastSAM
import os
import cv2
import torch
import numpy as np
import matplotlib
import clip
from fastsam import FastSAM, FastSAMPrompt

model = FastSAM(FAST_SAM_CHECKPOINT_PATH)
everything_results = model(DOGImage_PATH, device=DEVICE, retina_masks=True, imgsz=1024,
conf=0.4, iou=0.9,)
prompt_process = FastSAMPrompt(DOGImage_PATH, everything_results, device=DEVICE)

ann = prompt_process.everything_prompt()
prompt_process.plot(annotations=ann,output_path='./output/dogSegmented.jpg',)

ann = prompt_process.text_prompt(text='a photo of a dog')
prompt_process.plot(annotations=ann,output_path='./output/dogPromptPhoto.jpg',)
< /code>
Alles_Prompt funktioniert gut, und ich sehe das generierte Bild im Ordner. Der text_prompt verursacht jedoch Fehler < /p>
 NameError                                 Traceback (most recent call last)
 in ()
1 # text prompt
----> 2 ann = prompt_process.text_prompt(text='a photo of a dog')
3 prompt_process.plot(annotations=ann,output_path='./output/dogPromptPhoto.jpg',)

/content/drive/MyDrive/Vision/FastSAM/fastsam/prompt.py in text_prompt(self, text)
443         format_results = self._format_results(self.results[0], 0)
444         cropped_boxes, cropped_images, not_crop, filter_id, annotations =
self._crop_image(format_results)
--> 445         clip_model, preprocess = clip.load('ViT-B/32', device=self.device)
446         scores = self.retrieve(clip_model, preprocess, cropped_boxes, text,
device=self.device)
447         max_idx = scores.argsort()

NameError: name 'clip' is not defined
Anfangs habe ich! fährt fort. Ich prüfe
! Python -c "clip importieren; print ('clip ist installiert!')" < /P>
Und das Ergebnis ist in Ordnung. Jede Hilfe wird sehr geschätzt.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post