visionTransformer window平台下报错

  • 错误:
clike 复制代码
KeyError: 'Transformer/encoderblock_0/MlpBlock_3/Dense_0kernel is not a file in the archive'
  • 解决方法:

修改这个函数即可,主要原因是Linux系统与window系统路径分隔符不一样导致

clike 复制代码
    def load_from(self, weights, n_block):
        ROOT = f"Transformer/encoderblock_{n_block}"
        with torch.no_grad():
            # query_weight = np2th(weights[pjoin(ROOT, ATTENTION_Q, "kernel")]).view(self.hidden_size, self.hidden_size).t()
            # key_weight = np2th(weights[pjoin(ROOT, ATTENTION_K, "kernel")]).view(self.hidden_size, self.hidden_size).t()
            # value_weight = np2th(weights[pjoin(ROOT, ATTENTION_V, "kernel")]).view(self.hidden_size, self.hidden_size).t()
            # out_weight = np2th(weights[pjoin(ROOT, ATTENTION_OUT, "kernel")]).view(self.hidden_size, self.hidden_size).t()
            query_weight = np2th(weights[(ROOT + '/' + ATTENTION_Q + "/kernel")]).view(self.hidden_size,self.hidden_size).t()
            key_weight = np2th(weights[(ROOT + '/' + ATTENTION_K + "/kernel")]).view(self.hidden_size,self.hidden_size).t()
            value_weight = np2th(weights[(ROOT + '/' + ATTENTION_V + "/kernel")]).view(self.hidden_size,self.hidden_size).t()
            out_weight = np2th(weights[(ROOT + '/' + ATTENTION_OUT + "/kernel")]).view(self.hidden_size,self.hidden_size).t()

            # query_bias = np2th(weights[pjoin(ROOT, ATTENTION_Q, "bias")]).view(-1)
            # key_bias = np2th(weights[pjoin(ROOT, ATTENTION_K, "bias")]).view(-1)
            # value_bias = np2th(weights[pjoin(ROOT, ATTENTION_V, "bias")]).view(-1)
            # out_bias = np2th(weights[pjoin(ROOT, ATTENTION_OUT, "bias")]).view(-1)
            query_bias = np2th(weights[(ROOT + '/' + ATTENTION_Q + "/bias")]).view(-1)
            key_bias = np2th(weights[(ROOT + '/' + ATTENTION_K + "/bias")]).view(-1)
            value_bias = np2th(weights[(ROOT + '/' + ATTENTION_V + "/bias")]).view(-1)
            out_bias = np2th(weights[(ROOT + '/' + ATTENTION_OUT + "/bias")]).view(-1)

            self.attn.query.weight.copy_(query_weight)
            self.attn.key.weight.copy_(key_weight)
            self.attn.value.weight.copy_(value_weight)
            self.attn.out.weight.copy_(out_weight)
            self.attn.query.bias.copy_(query_bias)
            self.attn.key.bias.copy_(key_bias)
            self.attn.value.bias.copy_(value_bias)
            self.attn.out.bias.copy_(out_bias)

            mlp_weight_0 = np2th(weights[(ROOT + '/' + FC_0 + "/kernel")]).t()
            mlp_weight_1 = np2th(weights[(ROOT + '/' + FC_1 + "/kernel")]).t()
            mlp_bias_0 = np2th(weights[(ROOT + '/' + FC_0 +"/bias")]).t()
            mlp_bias_1 = np2th(weights[(ROOT + '/' + FC_1 + "/bias")]).t()

            self.ffn.fc1.weight.copy_(mlp_weight_0)
            self.ffn.fc2.weight.copy_(mlp_weight_1)
            self.ffn.fc1.bias.copy_(mlp_bias_0)
            self.ffn.fc2.bias.copy_(mlp_bias_1)

            self.attention_norm.weight.copy_(np2th(weights[(ROOT + '/' + ATTENTION_NORM + "/scale")]))
            self.attention_norm.bias.copy_(np2th(weights[(ROOT + '/' + ATTENTION_NORM +  "/bias")]))
            self.ffn_norm.weight.copy_(np2th(weights[(ROOT + '/' + MLP_NORM + "/scale")]))
            self.ffn_norm.bias.copy_(np2th(weights[(ROOT + '/' +  MLP_NORM + "/bias")]))
相关推荐
模型启动机4 分钟前
Langchain正式宣布,Deep Agents全面支持Skills,通用AI代理的新范式?
人工智能·ai·langchain·大模型·agentic ai
Python私教9 分钟前
别让 API Key 裸奔:基于 TRAE SOLO 的大模型安全配置最佳实践
人工智能
Python私教12 分钟前
Vibe Coding 体验报告:我让 TRAE SOLO 替我重构了 2000 行屎山代码,结果...
人工智能
prog_610313 分钟前
【笔记】和各大AI语言模型写项目——手搓SDN后得到的经验
人工智能·笔记·语言模型
zhangfeng113319 分钟前
深入剖析Kimi K2 Thinking与其他大规模语言模型(Large Language Models, LLMs)之间的差异
人工智能·语言模型·自然语言处理
paopao_wu36 分钟前
人脸检测与识别-InsightFace:特征向量提取与识别
人工智能·目标检测
Aevget1 小时前
MyEclipse全新发布v2025.2——AI + Java 24 +更快的调试
java·ide·人工智能·eclipse·myeclipse
IT_陈寒1 小时前
React 18并发渲染实战:5个核心API让你的应用性能飙升50%
前端·人工智能·后端
韩曙亮1 小时前
【人工智能】AI 人工智能 技术 学习路径分析 ① ( Python语言 -> 微积分 / 概率论 / 线性代数 -> 机器学习 )
人工智能·python·学习·数学·机器学习·ai·微积分
科普瑞传感仪器1 小时前
从轴孔装配到屏幕贴合:六维力感知的机器人柔性对位应用详解
前端·javascript·数据库·人工智能·机器人·自动化·无人机