1
+ import coremltools
2
+ import coremltools .proto .FeatureTypes_pb2 as ft
3
+
4
+ spec = coremltools .proto .Model_pb2 .Model ()
5
+ spec .specificationVersion = 1
6
+
7
+ new_input = spec .description .input .add ()
8
+ new_input .name = "image"
9
+ new_input .type .imageType .width = 256
10
+ new_input .type .imageType .height = 256
11
+ new_input .type .imageType .colorSpace = ft .ImageFeatureType .RGB
12
+
13
+ new_output = spec .description .output .add ()
14
+ new_output .name = "generatedImage"
15
+ new_output .type .imageType .width = 256
16
+ new_output .type .imageType .height = 256
17
+ new_output .type .imageType .colorSpace = ft .ImageFeatureType .RGB
18
+
19
+ # If you want the output to be a MultiArray instead of an image:
20
+ #new_output.type.multiArrayType.shape.extend([3, 256, 256])
21
+ #new_output.type.multiArrayType.dataType = ft.ArrayFeatureType.FLOAT32
22
+
23
+ new_prepro = spec .neuralNetwork .preprocessing .add ()
24
+ new_prepro .scaler .channelScale = 1.0
25
+ new_prepro .scaler .redBias = 0.0
26
+ new_prepro .scaler .greenBias = 0.0
27
+ new_prepro .scaler .blueBias = 0.0
28
+ new_prepro .featureName = spec .description .input [0 ].name
29
+
30
+ new_layer = spec .neuralNetwork .layers .add ()
31
+ new_layer .name = "test_layer"
32
+ new_layer .input .append (spec .description .input [0 ].name )
33
+ new_layer .output .append (spec .description .output [0 ].name )
34
+ new_layer .activation .linear .alpha = 1.0
35
+
36
+ print (spec .description )
37
+
38
+ coremltools .utils .save_spec (spec , "Image2Image.mlmodel" )
0 commit comments