U^2-Net: Going Deeper with Nested U-Structure for Salient Object Detection
Paper β’ 2005.09007 β’ Published
U-2-Net model converted to Apple Core ML format for macOS GPU-accelerated inference.
This model was converted from PyTorch to Core ML format using the following method:
torch.jit.trace β coremltools.convert()(1, 3, 320, 320) RGB image.mlpackage)import torch
import coremltools as ct
from u2net import U2NET
# Load model
u2net = U2NET(3, 1)
u2net.load_state_dict(torch.load("u2net.pth", map_location="cpu"))
u2net.eval()
# Trace and convert
dummy = torch.randn(1, 3, 320, 320)
traced = torch.jit.trace(u2net, dummy)
coreml_model = ct.convert(traced, inputs=[ct.ImageType(shape=(1, 3, 320, 320))])
coreml_model.save("U2NET.mlpackage")
Load the model in a macOS application using Core ML:
import CoreML
import Vision
let config = MLModelConfiguration()
config.computeUnits = .cpuAndGPU
let model = try U2NET(configuration: config)
Input:
image: 3-channel RGB image, 320Γ320 pixelsOutputs (7 saliency maps at different scales):
This repository contains a format conversion of the original U-2-Net model. All rights and credit belong to the original authors.
If you use this model, please cite the original paper:
@article{qin2020u2net,
title={U$^2$-Net: Going Deeper with Nested U-Structure for Salient Object Detection},
author={Qin, Xuebin and Zhang, Zichen and Huang, Chenyang and Dehghan, Masood and Zaiane, Osmar R and Jagersand, Martin},
journal={Pattern Recognition},
volume={106},
pages={107404},
year={2020},
publisher={Elsevier}
}