模型:
EfficientFormer-L1是EfficientFormer系列中的一个模型,由 Snap Research 开发。EfficientFormer模型旨在证明经过合理设计的Transformer模型可以在移动设备上实现极低的延迟同时保持高性能。
EfficientFormer-L1的这个检查点是在经过1000个epochs的训练之后得到的。
使用下面的代码来开始使用模型。
import requests
import torch
from PIL import Image
from transformers import EfficientFormerImageProcessor, EfficientFormerForImageClassificationWithTeacher
# Load a COCO image of two cats to test the model
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)
# Load preprocessor and pretrained model
model_name = "huggingface/efficientformer-l1-300"
processor = EfficientFormerImageProcessor.from_pretrained(model_name)
model = EfficientFormerForImageClassificationWithTeacher.from_pretrained(model_name)
# Preprocess input image
inputs = processor(images=image, return_tensors="pt")
# Inference
with torch.no_grad():
outputs = model(**inputs)
# Print the top ImageNet1k class prediction
logits = outputs.logits
scores = torch.nn.functional.softmax(logits, dim=1)
top_pred_class = torch.argmax(scores, dim=1)
print(f"Predicted class: {top_pred_class}")
该模型可用于图像分类和语义分割。在移动设备上(该模型在iPhone 12上进行了测试),CoreML检查点可以以低延迟执行这些任务。
虽然EfficientFormer中的大多数设计都是通用的,例如维度一致的设计和带有CONV-BN融合的4D块,但EfficientFormer的实际速度可能因其他平台而异。例如,如果GeLU在特定硬件和编译器上的支持不好,而HardSwish在特定硬件和编译器上的实现效率很高,则可能需要相应地修改运算符。提出的基于延迟的剪枝方法简单而快速。然而,如果不考虑搜索成本并进行基于枚举的蛮力搜索,则可能会获得更好的结果。
由于该模型是在Imagenet-1K上进行训练的,EfficientFormer模型中将体现 biases embedded in that dataset 。
该模型是在ImageNet-1K上进行训练的。
有关更多信息,请参阅 data card 。
训练过程在搭载NVIDIA A100和V100 GPU的集群上进行训练。
在ImageNet 10K上的Top-1准确率为80.2%。
@article{li2022efficientformer,
title={EfficientFormer: Vision Transformers at MobileNet Speed},
author={Li, Yanyu and Yuan, Geng and Wen, Yang and Hu, Eric and Evangelidis, Georgios and Tulyakov, Sergey and Wang, Yanzhi and Ren, Jian},
journal={arXiv preprint arXiv:2206.01191},
year={2022}
}