{"id":16881513,"url":"https://github.com/swhl/tinygpt-v","last_synced_at":"2025-03-20T03:35:01.934Z","repository":{"id":216798478,"uuid":"741240904","full_name":"SWHL/TinyGPT-V","owner":"SWHL","description":"整理学习版，博客依赖该仓库，不可删除","archived":false,"fork":false,"pushed_at":"2024-01-12T11:01:47.000Z","size":4923,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-25T05:41:29.172Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SWHL.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2024-01-10T01:37:25.000Z","updated_at":"2024-01-12T10:45:59.000Z","dependencies_parsed_at":"2024-01-12T23:54:50.343Z","dependency_job_id":null,"html_url":"https://github.com/SWHL/TinyGPT-V","commit_stats":null,"previous_names":["swhl/tinygpt-v"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SWHL%2FTinyGPT-V","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SWHL%2FTinyGPT-V/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SWHL%2FTinyGPT-V/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SWHL%2FTinyGPT-V/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SWHL","download_url":"https://codeload.github.com/SWHL/TinyGPT-V/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244544788,"owners_count":20469729,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T16:02:59.758Z","updated_at":"2025-03-20T03:35:01.913Z","avatar_url":"https://github.com/SWHL.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"#### QFormer作用？\nQFormer来自论文BCLI2工作中，用来弥补Frozen Image encoder和Frozen LLM之间的gap。\n基于Bert作为初始化的。\n\n\n#### 推理结构图\n```mermaid\nflowchart LR\n\nA(Image) --\u003e B(blip2_image_eval) --\u003e C(QFormer) --\u003e D(Liner)\n\nD --\u003e E(Linear) --\u003e F(get_context_emb)\n```\n\n#### prompt\n```text\nGive the following image: \u003cImg\u003eImageContent\u003c/Img\u003e. \"\n\"You will be able to see the image once I provide it to you. Please answer my questions.\n```\n融合方法：\n先将图像转为向量。将prompt除Image部分其他部分依次转为向量。\n再将两者mix，得到最终向量。\n\n```python\ndef get_context_emb(self, prompt, img_list):\n    device = img_list[0].device\n    prompt_segs = prompt.split(\"\u003cImageHere\u003e\")\n    assert (\n        len(prompt_segs) == len(img_list) + 1\n    ), \"Unmatched numbers of image placeholders and images.\"\n\n    seg_tokens = [\n        self.llama_tokenizer(seg, return_tensors=\"pt\", add_special_tokens=i == 0)\n        .to(device)\n        .input_ids  # only add bos to the first seg\n        for i, seg in enumerate(prompt_segs)\n    ]\n\n    seg_embs = [self.embed_tokens(seg_t) for seg_t in seg_tokens]\n\n    # TODO: 这里具体如何混合在一起的，需要Debug查看\n    mixed_embs = [emb for pair in zip(seg_embs[:-1], img_list) for emb in pair] + [\n        seg_embs[-1]\n    ]\n    mixed_embs = torch.cat(mixed_embs, dim=1)\n    return mixed_embs\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswhl%2Ftinygpt-v","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswhl%2Ftinygpt-v","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswhl%2Ftinygpt-v/lists"}