import torch
import numpy as np
import timm
# Create model for Embeddings extraction
resnet50 = timm.create_model('resnet50', pretrained=True)
resnet50_without_last_layer = torch.nn.Sequential(*(list(resnet50.children())[:-1]))
x = torch.FloatTensor(np.random.randn(1,3,224,224))
y = resnet50(x)
print(y.shape)
y_without_last_layer = resnet50_without_last_layer(x)
print(y_without_last_layer)
yy = torch.matmul(y_without_last_layer,resnet50.fc.weight.T)+resnet50.fc.bias
print(yy.shape)
print(torch.sum(y -yy))
timm resnet50不取最后一层
最新推荐文章于 2024-10-11 08:00:00 发布