Minimal example of using a model with multiple input tensors.
# create_model.py
import numpy as np
from keras.layers import Input, Concatenate, Flatten, Dense
from keras.models import Model
input_1 = Input(shape=(240, 320, 3))
input_2 = Input(shape=(100, 1, 1))
output = Dense(4)(Concatenate()([Flatten()(input_1), Flatten()(input_2)]))
model = Model(inputs=[input_1, input_2], outputs=output)
model.compile(loss='categorical_crossentropy', optimizer='nadam')
model.save('keras_model.h5', include_optimizer=False)
// main.cpp
#include <fdeep/fdeep.hpp>
int main()
{
const auto model = fdeep::load_model("fdeep_model.json");
const fdeep::tensor5 image(fdeep::shape5(1, 1, 240, 320, 3), 0.0f);
const fdeep::tensor5 values(fdeep::shape5(1, 1, 100, 1, 1), 0.0f);
const auto result = model.predict({image, values});
std::cout << fdeep::show_tensor5s(result) << std::endl;
}
python3 create_model.py
python3 convert_model.py keras_model.h5 fdeep_model.json
g++ -std=c++14 -O3 main.cpp
./a.out
output:
Loading json ... done. elapsed time: 0.089034 s
Running test 1 of 1 ... done. elapsed time: 0.002383 s
Loading, constructing, testing of fdeep_model.json took 0.134049 s overall.
[[[[0.0000]], [[0.0000]], [[0.0000]], [[0.0000]]]]