qubvel / segmentation_models

Segmentation models with pretrained backbones. Keras and TensorFlow Keras.
MIT License
4.73k stars 1.03k forks source link

File "/usr/local/lib/python3.8/dist-packages/tensorflow/lite/python/interpreter.py", line 915, in invoke self._interpreter.Invoke() RuntimeError: tensorflow/lite/kernels/concatenation.cc:158 t->dims->data[d] != t0->dims->data[d] (1 != 2)Node number 304 (CONCATENATION) failed to prepare. #574

Open Mayi-Keiji opened 1 year ago

Mayi-Keiji commented 1 year ago

Hi , I face a problem when complete the training with UNET + efficientnetb0 and convert the trained model to tflite format, I can convert it to tflite format, but after I call the invoke function, it raise an error as the title.

My envs like: image OS Platform and Distribution (e.g., Linux Ubuntu 20.04): TensorFlow installation (2.9.1+nv22.9):

Error code in tflite as below: ``import numpy as np import tensorflow as tf

def main():

interpreter = tf.lite.Interpreter(model_path="model.tflite") interpreter.allocate_tensors()

input_details = interpreter.get_input_details() output_details = interpreter.get_output_details()

input_shape = input_details[0]['shape'] input_data = np.array(np.random.random_sample(input_shape), dtype=np.float32) interpreter.set_tensor(input_details[0]['index'], input_data)

signatures = interpreter.get_signature_list() print(signatures)

interpreter.invoke() return

output_data = interpreter.get_tensor(output_details[0]['index']) print(output_data) if name == 'main': main() My model code is as below:

` ''' BACKBONE = 'efficientnetb0' BATCH_SIZE = 1 CLASSES = ["background", "target", "others"] LR = 0.0001 EPOCHS = 10

preprocess_input = sm.get_preprocessing(BACKBONE)

n_classes = 1 if len(CLASSES) == 1 else (len(CLASSES) + 1) # case for binary and multiclass segmentation activation = 'sigmoid' if n_classes == 1 else 'softmax'

model = sm.Unet(BACKBONE, classes=n_classes, activation=activation) ''' `