Я получаю следующую ошибку при попытке загрузить мою модель TensorFlow, используя следующие инструменты:
Xcode (Последний)
TensorFlow Experimental V1.1.1 (установлен с использованием модулей)
C ++
Я могу создать сеанс TensorFlow без проблем, и я могу прочитать модель TensorFlow в GraphDef, но когда я пытаюсь создать модель с использованием активного сеанса TensorFlow, яполучить следующую проблему.
Недопустимый аргумент: не зарегистрирован OpKernel для поддержки Op 'Equal' с этими атрибутами.
Зарегистрированные устройства:
[ЦП]
Зарегистрированные ядра:
device = 'CPU';T в [DT_FLOAT] [[Узел: Равный = Равный [T = DT_INT32, _output_shapes = [[]]] (Ранг, Равный)]]
Так выглядит мой код
tensorflow::Session* sessionPointer = nullptr;
const tensorflow::SessionOptions options;
tensorflow::Status newSessionStatus = tensorflow::NewSession(options, &sessionPointer);
[MachineLearning checkTensorflowStatus:newSessionStatus];
std::unique_ptr<tensorflow::Session> session(sessionPointer);
// Create a point to the tensorflow graph
tensorflow::GraphDef tensorflowGraph;
// Get the model file path
NSString* filePath = FilePathForResourceName(@"frozen_inference_graph", @"pb");
// Read the data into the TensorflowGraph
auto fileConverteredToProto = PortableReadFileToProto([filePath UTF8String], &tensorflowGraph);
// Create the tensorflow graph
tensorflow::Status createGraphStatus = session->Create(tensorflowGraph);
// Check the status of the tensorflow graph
[MachineLearning checkTensorflowStatus:createGraphStatus];
Я проверил, что путь к файлу, который он получает, правильный, и кажется, что он нормально загружает данные модели в GraphDef.Вот как я это делаю
// Finds the file path for the given file name
NSString* FilePathForResourceName(NSString* name, NSString* extension)
{
NSString* filePath = [[NSBundle mainBundle] pathForResource:name ofType:extension];
if (filePath == NULL)
{
LOG(ERROR) << "Could not find the TensorFlow model";
}
return filePath;
}
// Reads the file into the protobuf. This was taken from the TensorFlow example code
bool PortableReadFileToProto(const std::string& fileName, ::google::protobuf::MessageLite* proto)
{
// Create the input stream with the given file name
::google::protobuf::io::CopyingInputStreamAdaptor stream(new IfstreamInputStream(fileName));
// Set that this object owns the copying stream
stream.SetOwnsCopyingStream(true);
// Create a coded input stream
::google::protobuf::io::CodedInputStream codedStream(&stream);
// Set the byte limit, aparently having protos too big can causes issues, so we limit it.
codedStream.SetTotalBytesLimit(1024LL << 20, 512LL << 20);
// Parse the coded stream
return proto->ParseFromCodedStream(&codedStream);
}
Я читал о том, что OP не поддерживается в других публикациях, но Equal уже поддерживается, но он не работает так, как мне нужно для моего TensorFlow.модель.
Я также читал это руководство о том, как добавить новый OP. Tensorflow, как добавить новый OP
Но я не совсем понимаю, как все это работает, поэтому я изо всех сил пытаюсь запустить мою модель.
Я бы предпочелчтобы преобразовать мою модель TensorFlow в CoreML и использовать инструменты Swift CoreML, но есть проблема с преобразованием, когда Slice OP не поддерживается полностью и не может преобразовать мою модель.