模型:

rinna/japanese-clip-vit-b-16

英文

rinna/japanese-clip-vit-b-16

这是一个日本聊天的模型,由 rinna Co., Ltd. 训练。

请参阅 japanese-clip 以获取其他可用模型。

如何使用模型

  • 安装软件包
  • $ pip install git+https://github.com/rinnakk/japanese-clip.git
    
  • 运行
  • import io
    import requests
    from PIL import Image
    import torch
    import japanese_clip as ja_clip
    
    device = "cuda" if torch.cuda.is_available() else "cpu"
    
    
    model, preprocess = ja_clip.load("rinna/japanese-clip-vit-b-16", cache_dir="/tmp/japanese_clip", device=device)
    tokenizer = ja_clip.load_tokenizer()
    
    img = Image.open(io.BytesIO(requests.get('https://images.pexels.com/photos/2253275/pexels-photo-2253275.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260').content))
    image = preprocess(img).unsqueeze(0).to(device)
    encodings = ja_clip.tokenize(
        texts=["犬", "猫", "象"],
        max_seq_len=77,
        device=device,
        tokenizer=tokenizer, # this is optional. if you don't pass, load tokenizer each time
    )
    
    with torch.no_grad():
        image_features = model.get_image_features(image)
        text_features = model.get_text_features(**encodings)
        
        text_probs = (100.0 * image_features @ text_features.T).softmax(dim=-1)
    
    print("Label probs:", text_probs)  # prints: [[1.0, 0.0, 0.0]]
    

    模型架构

    该模型使用ViT-B/16 Transformer架构作为图像编码器,并使用12层BERT作为文本编码器。图像编码器是从 AugReg vit-base-patch16-224 model 初始化的。

    培训

    该模型使用 CC12M 训练,将字幕翻译成日语。

    许可证

    The Apache 2.0 license