keras_to_tensorflow icon indicating copy to clipboard operation
keras_to_tensorflow copied to clipboard

Error when using convert model on tensorflow for mobile

Open Onotoko opened this issue 7 years ago • 1 comments

Hi friends, After I converted keras model to tensorflow model, I run it on tensorflow for mobile. I got an error:

camera/CameraExampleViewController.mm:320] Running model failed:Invalid argument: Shape [-1,112,112,1] has negative dimensions [[Node: input_1 = Placeholderdtype=DT_FLOAT, shape=[?,112,112,1], _device="/job:localhost/replica:0/task:0/cpu:0"]]

Code on tensorflow for mobile: const int image_channels = 4;

assert(image_channels >= wanted_input_channels); tensorflow::Tensor image_tensor( tensorflow::DT_FLOAT, tensorflow::TensorShape( {1, wanted_input_height, wanted_input_width, wanted_input_channels})); auto image_tensor_mapped = image_tensor.tensor<float, 4>(); tensorflow::uint8 *in = sourceStartAddr; float *out = image_tensor_mapped.data(); for (int y = 0; y < wanted_input_height; ++y) { float *out_row = out + (y * wanted_input_width * wanted_input_channels); for (int x = 0; x < wanted_input_width; ++x) { const int in_x = (y * image_width) / wanted_input_width; const int in_y = (x * image_height) / wanted_input_height; tensorflow::uint8 *in_pixel = in + (in_y * image_width * image_channels) + (in_x * image_channels); float *out_pixel = out_row + (x * wanted_input_channels); for (int c = 0; c < wanted_input_channels; ++c) { out_pixel[c] = (in_pixel[c] * (1.0/255.0));// - input_mean) / input_std; } } }

CVPixelBufferUnlockBaseAddress(pixelBuffer, unlockFlags);

if (tf_session.get()) { std::vectortensorflow::Tensor outputs; tensorflow::Status run_status = tf_session->Run( {{input_layer_name, image_tensor}}, {output_layer_name}, {}, &outputs); if (!run_status.ok()) { LOG(ERROR) << "Running model failed:" << run_status; Thanks!

Onotoko avatar Jul 20 '18 03:07 Onotoko

I want convert model on tensorflow for mobile too,but i fail to convert model to tensorflow,May I ask you some questions

Syxxxxx avatar Oct 16 '19 13:10 Syxxxxx