CoreML lose precision

Hi all, I am new with CoreML. I got some problems with Converted TensorFlow(TS) Model using tfcoreml tools.


In the TS, I set 0 and 1 as input, and using "And" or "&" operator. The result i got :


TS Input: [[0.0, 1.0], [0.0, 0.0], [1.0, 1.0], [1.0, 0.0]]

iOS Input:[1.0,0.0]


Train 100 steps:

TS Output:

[[0.178767 ]

[0.00997119]

[0.80957186]

[0.16436805]]


iOS using [1.0, 0.0] got 0.16455078125


Train 1000 steps:

TS Output:

[[0.20152062]

[0.01846255]

[0.74348944]

[0.17764665]]


iOS using [1.0, 0.0] got 0.1778564453125


So, after compared with values, there is a litter differience. This result make big problem with my another Model. I don't know what to do the next. Is there something I miss about Convert Step or Some Setting I forget to set.

Replies

0.16455078125 - 0.16436805 = 0.0001827313


0.1778564453125 - 0.17764665 = 0.0002097953


This is only a very small difference. Core ML on the GPU uses 16-bit floats to do the computations. The precision of a 16-bit float is about 0.001 so you can expect these kinds of differences in the results.


If that is not enough precision for you, then you should run the model on the CPU instead of the GPU.