apple / apple/coremltools

Why is int64 input being converted to fp32 type?

Open
#830 2 comments 1 reaction 0 assignees View on GitHub
question triaged
Dominant language
Python
Stars
5.4k
Forks
850
Avg merge
4d 5h
Merged PRs (30d)
10

Description

## ❓Question

Why is int64 input being converted to fp32 type?
I have specified the input type to be int64 both in TensorFlow and in CoreML Converter. It seems that my specification doesn't work at all.

```python
import tensorflow as tf
import coremltools as ct
from coremltools.converters.mil.mil import types

tf_keras_model = tf.keras.Sequential(
[
tf.keras.layers.Input(shape=(2, ), dtype=tf.int64),
tf.keras.layers.Dense(10, activation=tf.nn.softmax),
]
)

tf_keras_model.summary()

inputT = ct.TensorType(shape=(1, 2), dtype=types.int64)
# Pass in `tf.keras.Model` to the Unified Conversion API
mlmodel = ct.convert(tf_keras_model, source="tensorflow", inputs=[inputT])
print(mlmodel._spec)
```

the converted spec's input is still FLOAT32

```
specificationVersion: 4
description {
input {
name: "input_4"
type {
multiArrayType {
shape: 1
shape: 2
dataType: FLOAT32
}
}
}
output {
name: "Identity"
type {
multiArrayType {
dataType: FLOAT32
}
}
}
metadata {
userDefined {
key: "com.github.apple.coremltools.source"
value: "tensorflow==2.2.0"
}
userDefined {
key: "com.github.apple.coremltools.version"
value: "4.0b2"
}
}
}
neuralNetwork {
layers {
name: "sequential_3/dense_3/Cast"
input: "input_4"
output: "sequential_3/dense_3/Cast"
activation {
linear {
alpha: 1.0
}
}
}
layers {
name: "sequential_3/dense_3/MatMul"
input: "sequential_3/dense_3/Cast"
output: "sequential_3/dense_3/MatMul"
batchedMatmul {
weightMatrixFirstDimension: 2
weightMatrixSecondDimension: 10
weights {
floatValue: -0.201704204082489
floatValue: 0.32254475355148315
floatValue: -0.23209309577941895
floatValue: 0.6677947640419006
floatValue: -0.010285377502441406
floatValue: -0.2716841399669647
floatValue: 0.5727601647377014
floatValue: -0.5159338712692261
floatValue: 0.2902577519416809
floatValue: -0.1514887809753418
floatValue: 0.48421818017959595
floatValue: -0.49535712599754333
floatValue: -0.5770056843757629
floatValue: -0.6723555326461792
floatValue: -0.23098108172416687
floatValue: -0.11880236864089966
floatValue: -0.4196607172489166
floatValue: 0.4131630063056946
floatValue: 0.04167008399963379
floatValue: 0.4192139506340027
}
}
}
layers {
name: "sequential_3/dense_3/Softmax"
input: "sequential_3/dense_3/MatMul"
output: "Identity"
softmaxND {
axis: -1
}
}
arrayInputShapeMapping: EXACT_ARRAY_MAPPING
imageInputShapeMapping: RANK4_IMAGE_MAPPING
}
```

## System Information
- coremltools 4.02b
- python 3.7
- TensorFlow 2.2

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.