NotImplementedError: Conversion for TF op 'MLCMatMul' not implemented.
While converting a Keras model to a CoreML model, I receive the following error: "NotImplementedError: Conversion for TF op 'MLCMatMul' not implemented."
Stack Trace
raise NotImplementedError(msg)
NotImplementedError: Conversion for TF op 'MLCMatMul' not implemented.
name: "sequential/dense/MLCMatMul"
op: "MLCMatMul"
input: "dense_input"
input: "sequential/dense/MLCMatMul/ReadVariableOp"
attr {
key: "T"
value {
type: DT_FLOAT
}
}
attr {
key: "input_rank"
value {
i: 2
}
}
attr {
key: "num_args"
value {
i: 0
}
}
attr {
key: "transpose_a"
value {
b: false
}
}
attr {
key: "transpose_b"
value {
b: false
}
}
To Reproduce
- Please add a minimal code example that can reproduce the error when running it.
import numpy as np
import pandas as pd
from sklearn.metrics import mean_squared_error
from sklearn.preprocessing import StandardScaler
from tensorflow.keras.layers import Dense, Dropout
from tensorflow.keras.models import Sequential
from tensorflow.keras.optimizers import SGD, Adam
from tensorflow.python.keras.utils.np_utils import to_categorical
model = Sequential()
model.add(Dense(128, activation='relu', input_shape=(3,)))
model.add(Dropout(0.25))
model.add(Dense(512, activation='relu'))
model.add(Dropout(0.25))
model.add(Dense(512, activation='relu'))
model.add(Dropout(0.25))
model.add(Dense(128, activation='relu'))
model.add(Dense(13, activation='softmax'))
print(model.summary())
sgd = SGD(lr=0.01)
model.compile(loss='categorical_crossentropy', optimizer=Adam(), metrics=['accuracy'])
history = model.fit(X_train, dummy_y, epochs=220, verbose=1, batch_size=16, validation_data=(X_test, y_val))
model.save('NN models/model7')
pred = model.predict(X_test)
y_pred = pred.argmax(axis=1)
for i in range(len(y_pred)):
print('True : {} Pred : {}'.format(y_test[i], y_pred[i]))
mean_squared_error(y_test, y_pred)
print(mean_squared_error(y_test.astype(int), y_pred))
To convert to CoreML:
import coremltools
new_model = tf.keras.models.load_model('/Users/aakansha/PycharmProjects/NN models/model7')
coreml_model = coremltools.converters.convert(model=new_model)
output = "nn_model.mlmodel"
coreml_model.save(output)
System environment (please complete the following information):
- coremltools version: 5.2.0
- OS (e.g. MacOS version or Linux type): macOS Monterey Version 12.1
- TensorFlow version: tensorflow 0.1a3
@aakansha-oncoshot - please share the rest of the code to reproduce this bug. How are you calling coremltools.convert?
@aakansha-oncoshot - please share the rest of the code to reproduce this bug. How are you calling
coremltools.convert?
Have updated the code to show how I'm calling coremltools.convert, thank you!
I can't train your model. The following variables are not defined in your code: X_train, dummy_y, X_test, and y_val.
However I believe this issue has been fixed in the latest version of coremltools. Using coremltools version 6.0b1. I'm able to run the following code without error:
import coremltools
from tensorflow.keras.layers import Dense, Dropout
from tensorflow.keras.models import Sequential
model = Sequential()
model.add(Dense(128, activation='relu', input_shape=(3,)))
model.add(Dropout(0.25))
model.add(Dense(512, activation='relu'))
model.add(Dropout(0.25))
model.add(Dense(512, activation='relu'))
model.add(Dropout(0.25))
model.add(Dense(128, activation='relu'))
model.add(Dense(13, activation='softmax'))
coreml_model = coremltools.converters.convert(model=model)
Seems like this issue has been fixed. Since we have not heard back, I'm going to close this issue.