终极指南:convnext_tiny.in12k_ft_in1k 快速上手教程(附完整代码) 终极指南convnext_tiny.in12k_ft_in1k 快速上手教程附完整代码【免费下载链接】convnext_tiny.in12k_ft_in1k项目地址: https://ai.gitcode.com/hf_mirrors/timm/convnext_tiny.in12k_ft_in1kconvnext_tiny.in12k_ft_in1k 是一款基于 ConvNeXt 架构的图像分类模型由 Ross Wightman 在 timm 库中实现。该模型先在 ImageNet-12k包含 11821 个类别的 ImageNet-22k 子集上进行预训练然后在 ImageNet-1k 上进行微调非常适合图像分类、特征提取等计算机视觉任务。模型核心特性概览 关键技术参数模型类型图像分类/特征骨干网络参数量28.6M计算量GMACs4.5激活值M13.4输入尺寸训练时 224×224测试时 288×288支持数据集ImageNet-1k微调、ImageNet-12k预训练性能优势在 RTX 3090 显卡上该模型以 256 batch size 运行时可达到2433.7 样本/秒的推理速度Top-1 准确率为 84.186%Top-5 准确率为 97.124%在轻量级模型中表现出色。快速开始环境准备 ⚙️安装必要依赖# 克隆仓库 git clone https://gitcode.com/hf_mirrors/timm/convnext_tiny.in12k_ft_in1k cd convnext_tiny.in12k_ft_in1k # 安装依赖 pip install timm torch pillow urllib3模型文件说明项目目录下包含以下核心文件模型权重model.safetensors、pytorch_model.bin配置文件config.json包含输入尺寸、均值/标准差等关键参数说明文档README.md完整技术细节实战教程三大核心功能 1. 图像分类最常用场景通过以下代码可快速实现对任意图像的分类from urllib.request import urlopen from PIL import Image import timm import torch # 加载图像可替换为本地图片路径 img Image.open(urlopen( https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png )) # 加载预训练模型 model timm.create_model(convnext_tiny.in12k_ft_in1k, pretrainedTrue) model model.eval() # 获取模型专用数据转换自动处理归一化和尺寸调整 data_config timm.data.resolve_model_data_config(model) transforms timm.data.create_transform(**data_config, is_trainingFalse) # 执行推理 output model(transforms(img).unsqueeze(0)) # 添加 batch 维度 top5_prob, top5_idx torch.topk(output.softmax(dim1)*100, k5) # 输出结果 print(Top 5 预测类别及概率) for prob, idx in zip(top5_prob[0], top5_idx[0]): print(f类别 {idx}: {prob:.2f}%)2. 特征图提取用于可视化或下游任务提取模型中间层特征可用于目标检测、语义分割等任务model timm.create_model( convnext_tiny.in12k_ft_in1k, pretrainedTrue, features_onlyTrue, # 启用特征提取模式 ) model model.eval() output model(transforms(img).unsqueeze(0)) # 输出为特征图列表 # 打印各层特征图形状 for i, feature_map in enumerate(output): print(f特征层 {i1} 形状: {feature_map.shape}) # 输出示例 # 特征层 1 形状: torch.Size([1, 96, 56, 56]) # 特征层 2 形状: torch.Size([1, 192, 28, 28]) # 特征层 3 形状: torch.Size([1, 384, 14, 14]) # 特征层 4 形状: torch.Size([1, 768, 7, 7])3. 图像嵌入向量生成用于相似度计算生成图像的固定长度向量表示可用于检索、聚类等任务# 方法一移除分类头直接输出特征 model timm.create_model( convnext_tiny.in12k_ft_in1k, pretrainedTrue, num_classes0, # 设为 0 移除最终分类层 ) # 方法二显式调用特征提取接口 output model.forward_features(transforms(img).unsqueeze(0)) # 未池化特征 output model.forward_head(output, pre_logitsTrue) # 池化后特征向量 print(f图像嵌入向量形状: {output.shape}) # 输出: torch.Size([1, 768])进阶配置优化推理性能 ⚡调整输入尺寸根据硬件性能和精度需求可修改测试输入尺寸data_config[input_size] (3, 384, 384) # 增大尺寸可能提升精度但增加计算量 transforms timm.data.create_transform(**data_config, is_trainingFalse)使用混合精度推理在支持的 GPU 上启用 AMP 加速with torch.cuda.amp.autocast(): output model(transforms(img).unsqueeze(0).cuda())模型对比为何选择 convnext_tiny.in12k_ft_in1k模型Top1 准确率参数量M速度样本/秒convnext_tiny.in12k_ft_in1k84.19%28.62433.7convnext_small.in12k_ft_in1k85.17%50.21474.3convnext_base.fb_in1k83.82%88.61054.0相比同系列模型convnext_tiny.in12k_ft_in1k 在速度与精度间取得了极佳平衡适合边缘设备和实时应用场景。引用与致谢如果使用本模型请引用以下论文misc{rw2019timm, author {Ross Wightman}, title {PyTorch Image Models}, year {2019}, publisher {GitHub}, journal {GitHub repository}, doi {10.5281/zenodo.4414861}, howpublished {\url{https://github.com/huggingface/pytorch-image-models}} } article{liu2022convnet, author {Zhuang Liu and Hanzi Mao and Chao-Yuan Wu and Christoph Feichtenhofer and Trevor Darrell and Saining Xie}, title {A ConvNet for the 2020s}, journal {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)}, year {2022}, }本模型的训练得到了 TRC 项目和 Lambda Labs 云服务的支持。【免费下载链接】convnext_tiny.in12k_ft_in1k项目地址: https://ai.gitcode.com/hf_mirrors/timm/convnext_tiny.in12k_ft_in1k创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

相关新闻

最新新闻

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现 【免费下载链接】serenity The Serenity Operating System 🐞 项目地址: https://gitcode.com/GitHub_Trending/se/serenity 导读 本文以 getopt(3) 手册 为核心&a…

2026/9/23 4:54:42
轻量服务器还是ECS?大促云服务器选购与避坑实战指南

轻量服务器还是ECS?大促云服务器选购与避坑实战指南

每年大促节点,群里永远有人在问同一个问题:“38元的轻量服务器到底怎么抢?为什么我每次点进去都是已售罄?68元直购和99元的ECS我到底选哪个?”作为一个常年帮团队和自己采购云服务器的老用户,我太清楚这种纠…

2026/9/23 8:01:55
为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南

为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南

为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南 【免费下载链接】agents Multi-harness agentic plugin marketplace for Claude Code, Codex, Cursor, OpenCode, GitHub Copilot, and Google Antigravity 项目地址:…

2026/9/23 8:02:11
PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署

PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署

PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署 【免费下载链接】PaddleOCR Turn any PDF or image document into structured data for your AI. A powerful, lightweight OCR toolkit that bridges the gap between i…

2026/9/23 8:01:38
Spring源码解析:构造器注入的类型转换与候选匹配机制

Spring源码解析:构造器注入的类型转换与候选匹配机制

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/9/23 8:01:21
openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由

openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由

openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由 【免费下载链接】openai-agents-python A lightweight, powerful framework for multi-agent workflows 项目地址: https://gitcode.com/GitHub_Trending/op/openai-agents-pyth…

2026/9/23 8:02:28

日新闻

周新闻