Skip to content

转模型报错 #9

Description

@kc-w

执行代码:
def export_embedding_model():
sam_checkpoint = "D:/Anaconda3/envs/sam_vit_h_4b8939.pth"
model_type = "vit_h"
device = "cpu"
sam = sam_model_registrymodel_type
sam.to(device=device)
image = cv2.imread('./images/truck.jpg')
target_length = sam.image_encoder.img_size
pixel_mean = sam.pixel_mean
pixel_std = sam.pixel_std
img_size = sam.image_encoder.img_size
inputs = pre_processing(image, target_length, device,pixel_mean,pixel_std,img_size)
onnx_model_path = model_type+"_"+"embedding.onnx"
dummy_inputs = {
"images": inputs
}
output_names = ["image_embeddings"]
image_embeddings = sam.image_encoder(inputs).cpu().numpy()
print('image_embeddings', image_embeddings.shape)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=torch.jit.TracerWarning)
warnings.filterwarnings("ignore", category=UserWarning)
with open(onnx_model_path, "wb") as f:
torch.onnx.export(
sam.image_encoder,
tuple(dummy_inputs.values()),
f,
export_params=True,
verbose=False,
opset_version=17,
do_constant_folding=True,
input_names=list(dummy_inputs.keys()),
output_names=output_names,
# dynamic_axes=dynamic_axes,
)

提示错误
image

环境:
image

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions