Изначально я думал об использовании C API tensorflow. Для этого я преобразовал файл (.h5) в (.pb) — просто чтобы сделать его совместимым с найденным примером:
Код Python для .h5 > . конверсия пб
Код: Выделить всё
import tensorflow as tf
model = tf.keras.models.load_model('path_to_your_model.h5')
tf.saved_model.save(model, 'saved_model_directory')
Код: Выделить всё
#include
int main() {
// Initialize TensorFlow
TF_Status* status = TF_NewStatus();
TF_SessionOptions* options = TF_NewSessionOptions();
TF_Session* session = TF_NewSession(options, status);
TF_Buffer* run_options = NULL;
const char* tags = "serve"; // Use "serve" tag for inference
// Load the SavedModel
TF_Graph* graph = TF_NewGraph();
TF_Buffer* saved_model_buffer = TF_ReadFile("path_to_saved_model_directory", status);
TF_SessionRun(session, run_options,
NULL, NULL, 0,
NULL, NULL, 0,
NULL, 0,
&graph, status);
TF_DeleteBuffer(saved_model_buffer);
// Perform inference
// Construct input tensor, run session, get output tensor, etc.
// Clean up
TF_DeleteGraph(graph);
TF_DeleteSession(session, status);
TF_DeleteSessionOptions(options);
TF_DeleteStatus(status);
return 0;
}
Код: Выделить всё
C:\Users\dossa\AppData\Local\Temp\ccTGNpqh.o:main.c:(.text+0xf): undefined reference to `_imp__TF_NewStatus'
C:\Users\dossa\AppData\Local\Temp\ccTGNpqh.o:main.c:(.text+0x1a): undefined reference to `_imp__TF_NewSessionOptions'
C:\Users\dossa\AppData\Local\Temp\ccTGNpqh.o:main.c:(.text+0x25): undefined reference to `_imp__TF_NewGraph'
C:\Users\dossa\AppData\Local\Temp\ccTGNpqh.o:main.c:(.text+0xd8): undefined reference to `_imp__TF_NewBuffer'
C:\Users\dossa\AppData\Local\Temp\ccTGNpqh.o:main.c:(.text+0x103): undefined reference to `_imp__TF_NewImportGraphDefOptions'
C:\Users\dossa\AppData\Local\Temp\ccTGNpqh.o:main.c:(.text+0x12d): undefined reference to `_imp__TF_GraphImportGraphDef'C:\Users\dossa\AppData\Local\Temp\ccTGNpqh.o:main.c:(.text+0x13b): undefined reference to `_imp__TF_DeleteImportGraphDefOptions'
C:\Users\dossa\AppData\Local\Temp\ccTGNpqh.o:main.c:(.text+0x159): undefined reference to `_imp__TF_NewSession'
C:\Users\dossa\AppData\Local\Temp\ccTGNpqh.o:main.c:(.text+0x16b): undefined reference to `_imp__TF_GetCode'
C:\Users\dossa\AppData\Local\Temp\ccTGNpqh.o:main.c:(.text+0x182): undefined reference to `_imp__TF_Message'
C:\Users\dossa\AppData\Local\Temp\ccTGNpqh.o:main.c:(.text+0x1a7): undefined reference to `_imp__TF_DeleteBuffer'
C:\Users\dossa\AppData\Local\Temp\ccTGNpqh.o:main.c:(.text+0x1b5): undefined reference to `_imp__TF_DeleteSessionOptions'
C:\Users\dossa\AppData\Local\Temp\ccTGNpqh.o:main.c:(.text+0x1cb): undefined reference to `_imp__TF_DeleteSession'
C:\Users\dossa\AppData\Local\Temp\ccTGNpqh.o:main.c:(.text+0x1d9): undefined reference to `_imp__TF_DeleteGraph'
C:\Users\dossa\AppData\Local\Temp\ccTGNpqh.o:main.c:(.text+0x1e7): undefined reference to `_imp__TF_DeleteStatus'
collect2.exe: error: ld returned 1 exit status
Подробнее здесь: https://stackoverflow.com/questions/783 ... ave-a-file