Method

install

git clone https://github.com/daa233/generative-inpainting-pytorch.git
cd generative-inpainting-pytorch
pip install pyyaml==5.4.1

Inference

python test_single.py --checkpoint_path path_to_pretrained_model_dir --image your_image.png --mask examples/center_mask_256.png --output examples/output.png
input

--

--

Handle models with multiple inputs

Some machine learning models require multiple inputs.
How do weconvert such models to CoreML?

Multi inputs

Method

Suppose we transform a model with two inputs, x and y.

import torch
import coremltools as ct

traced_model = torch.jit.trace(model, (x,y)) # convert to torchscript
mlmodel = ct.convert(traced_model, inputs=[ct.TensorType(shape=x.shape),ct.TensorType(shape=y.shape)]) # convert to coreml

Usage in Swift

Run the converted model in Swift.

do {
let model = try myModel().model
let input = myModelInput(x: x, y: y) // x and y are MLMultiArray in this case.
let out = try model.prediction(from: input)
} catch let error {
print(error)
}

🐣

I’m a freelance engineer.
Work consultation
Please feel free to contact us with a brief development description.
rockyshikoku@gmail.com

I am making an app that uses Core ML and ARKit.
We send machine learning / AR related information.

GitHub

Twitter
Medium

--

--