junyanz / pytorch-CycleGAN-and-pix2pix

Image-to-Image Translation in PyTorch
Other
23.05k stars 6.31k forks source link

Hi, I tried to convert into coreml. #867

Open HeoJinLareine opened 4 years ago

HeoJinLareine commented 4 years ago

I've converted into onnx, then mlmodel. But the result's input/ output was MLMultiarray.

How can I change Just input/output as image using my original pretrained model?

kitashige commented 4 years ago

@HeoJinLareine

Can't it be achieved with the following code?

===Comand Line===

pip install coremltools==4.0b3

===Python Code==== import coremltools
from coremltools.proto import FeatureTypes_pb2 as ft
 spec = coremltools.utils.load_spec('./CycleGAN.mlmodel')

builder = coremltools.models.neural_network.NeuralNetworkBuilder(spec=spec)

rgb = ft.ImageFeatureType.ColorSpace.Value('RGB') input_image_type = builder.spec.description.input[0].type.imageType input_image_type.width = 256
input_image_type.height = 256
input_image_type.colorSpace = rgb

output_image_type=builder.spec.description.output[0].type.imageType output_image_type.width = 256
output_image_type.height = 256
output_image_type.colorSpace = rgb

builder.inspect_input_features() builder.inspect_output_features()

mlmodel_modified = coremltools.models.MLModel(spec) mlmodel_modified.save('./NewCycleGAN.mlmodel')