Open maciej3031 opened 2 years ago
I'm not able to reproduce this problem. I get the following TensorFlow error by just declaring your class:
AlreadyExistsError: Another metric with the same name already exists.
Hey, that's very strange, everything works fine for me. To reproduce it once again I used the following commands:
conda create -n test_env python=3.9
conda activate test_env
conda install tensorflow==2.6.0
python3.9 -m pip install coremltools
conda install pillow
python3.9 coreml.py
where coreml.py
is:
import os
import numpy as np
import tensorflow as tf
import coremltools as ct
from PIL import Image
img01 = np.random.rand(256, 256, 3).astype(np.float32) img0255 = (img01*255).astype(np.uint8) img_pil = Image.fromarray(img0255)
class ProblemLayer(tf.keras.layers.Layer): def init(self, kwargs): super(ProblemLayer, self).init(kwargs)
def call(self, image):
B, H, W = tf.shape(image)[0], tf.shape(image)[1], tf.shape(image)[2]
proj_mat = tf.convert_to_tensor([[1.22, 0.09, -39.61, -0.09, 1.22, -6.17, 0.0, 0.0]], dtype=tf.float32)
proj_mat = tf.repeat(proj_mat, B, 0)
image = tf.raw_ops.ImageProjectiveTransformV2(
images=image,
transforms=proj_mat,
output_shape=[H, W],
interpolation='BILINEAR',
fill_mode='CONSTANT')
return image
inp = tf.keras.layers.Input(shape=(256, 256, 3), name="combined_input") x = ProblemLayer()(inp) model = tf.keras.models.Model(inputs=inp, outputs=x)
mlmodel = ct.convert(model, inputs=[ct.ImageType(shape=(1, 256, 256, 3), scale=1.0/255.0)], convert_to="mlprogram")
pred_coreml = mlmodel.predict({'combined_input': img_pil})
and the error is still:
Traceback (most recent call last):
File "/Users/maciej3031/projects/coreml.py", line 33, in
I think you're using non-standard conda channels. When running step 3, I get a PackagesNotFoundError
.
If I follow your directions but install TensorFlow 2.6.0 using pip
, I get the same error as before when declaring your class.
I use mini conda forge from https://developer.apple.com/metal/tensorflow-plugin/ and tensorflow: conda-forge/osx-arm64::tensorflow-2.6.0-py39hb1906d9_1
Did anyone succeed to reproduce it?
Ok, so you're on an M1 machine and using tensorflow-metal, those are important details.
Did anyone succeed to reproduce it?
Yes, using tensorflow-metal on an M1 machine, I can reproduce this problem.
Yes, it's on M1. However, it occurs on both tensorflow-metal
and usual tensorflow
.
🐞Describe the bug
When you have an ImageProjectiveTransformV2 op in tensorflow model and try to convert it to coreml then it raises the following exception. Is seems that
affine
ops does not support the "unnormalized"coordinates_mode
. Do you plan to fix it in the near future? Affine transformation is quite commonly used in computer vision problems nowadays and it would be really nice to use it during conversion from tensorflow 🙏Trace
Minimal code to Reproduce
System environment
Additional context
Apart from this bug, do you plan to add support for ImageProjectiveTransformV3?