Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于调用cn_clip进行特征提取报错格式错误的问题 #371

Open
Seing-yu opened this issue Dec 2, 2024 · 0 comments
Open

关于调用cn_clip进行特征提取报错格式错误的问题 #371

Seing-yu opened this issue Dec 2, 2024 · 0 comments

Comments

@Seing-yu
Copy link

Seing-yu commented Dec 2, 2024

Text的特征提取代码如下:
import cn_clip.clip as clip
from cn_clip.clip import load_from_name, available_models
class TextCLIPModel(nn.Module):

def __init__(self, config, device):
    super().__init__()
    self.device = device
    self.model, self.preprocess = self._load_model(config)

def _load_model(self, config):
    model, preprocess = load_from_name(config.clip_model_name, download_root=config.download_root)
    model.to(self.device)  # 将模型移动到指定设备
    model.eval()
    return model, preprocess

def forward(self, texts):
    tokens = clip.tokenize(texts).to(self.device)
    with torch.no_grad():
        text_features = self.model.encode_text(tokens)
        text_features /= text_features.norm(dim=-1, keepdim=True)  # 归一化特征
    return text_features

image
输入的文本txt格式:
image
输入的data.json格式如下:
image
输入的img是data文件夹:
image
我想问一下,这样输入数据是调用有问题,还是原始数据格式有问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant