Humphreykowl commited on
Commit
2bf52c2
·
verified ·
1 Parent(s): 5946c21

Update models/model_manager.py

Browse files
Files changed (1) hide show
  1. models/model_manager.py +1 -26
models/model_manager.py CHANGED
@@ -1,29 +1,4 @@
1
- def load_caption_model(self):
2
- """加载图像描述模型"""
3
- if self.caption_model is None:
4
- start_time = time.time()
5
- logger.info("正在加载BLIP图像描述模型...")
6
-
7
- try:
8
- self.caption_processor = BlipProcessor.from_pretrained(
9
- self.model_config["caption_model"],
10
- cache_dir=self.cache_dir
11
- )
12
-
13
- self.caption_model = BlipForConditionalGeneration.from_pretrained(
14
- self.model_config["caption_model"],
15
- cache_dir=self.cache_dir,
16
- torch_dtype=torch.float16 if self.device == "cuda" else torch.float32
17
- ).to(self.device)
18
-
19
- self.load_times["caption_model"] = time.time() - start_time
20
- self.last_used["caption_model"] = time.time()
21
- logger.info(f"BLIP图像描述模型加载完成,用时 {self.load_times['caption_model']:.2f} 秒")
22
- except Exception as e:
23
- logger.error(f"加载BLIP图像描述模型失败: {e}")
24
-
25
-
26
- def caption_image(self, image: Image.Image) -> str:
27
  """对图像生成描述"""
28
  if self.caption_model is None or self.caption_processor is None:
29
  self.load_caption_model()
 
1
+ def caption_image(self, image) -> str:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  """对图像生成描述"""
3
  if self.caption_model is None or self.caption_processor is None:
4
  self.load_caption_model()