我在使用 Salesforce/blip-image-captioning-base 模型加载 BLIP 处理器和图像字幕模型时遇到问题。我的脚本在尝试加载时似乎卡住了...
我在加载 BLIP 处理器和模型以使用该 Salesforce/blip-image-captioning-base
模型进行图像字幕制作时遇到了问题。我的脚本在尝试加载处理器和模型时似乎卡住了。以下是我的设置和我正在使用的脚本的详细信息。
import logging
from transformers import BlipProcessor, BlipForConditionalGeneration, __version__ as transformers_version
from PIL import Image, __version__ as pillow_version
import torch
# Enable logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Log versions
logger.info(f"Transformers version: {transformers_version}")
logger.info(f"Torch version: {torch.__version__}")
logger.info(f"Pillow version: {pillow_version}")
# Check CUDA availability
logger.info(f"CUDA available: {torch.cuda.is_available()}")
# Load an image
image_path = "./data/images/LHorgan_JDFAirWing_279.jpg"
try:
image = Image.open(image_path)
logger.info("Image loaded successfully")
except Exception as e:
logger.error(f"Failed to load image: {e}")
# Load the processor and model with detailed logging
try:
logger.info("Loading processor...")
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
logger.info("Processor loaded successfully")
logger.info("Loading model...")
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
logger.info("Model loaded successfully")
except Exception as e:
logger.error(f"Failed to load processor or model: {e}")
# Check if the model and processor are correctly loaded
if 'processor' in locals():
logger.info("Processor is ready for use.")
else:
logger.error("Processor was not loaded properly.")
if 'model' in locals():
logger.info("Model is ready for use.")
else:
logger.error("Model was not loaded properly.")
该脚本记录以下内容,然后在加载处理器时卡住:
INFO:__main__:Transformers version: 4.42.3
INFO:__main__:Torch version: 2.2.2
INFO:__main__:Pillow version: 10.3.0
INFO:__main__:CUDA available: False
INFO:__main__:Image loaded successfully
INFO:__main__:Loading processor...
它似乎无限期地挂在“正在加载处理器...”。我已确保我的互联网连接稳定,并检查了我的 Python 环境设置。尽管如此,处理器和模型似乎仍未成功加载。
有人能提供关于如何解决此问题的见解或建议吗?我可能遗漏了哪些具体配置或步骤?如能提供任何帮助,我将不胜感激。
先感谢您!