@@ -33,11 +33,9 @@ int main()
3333 auto num_of_threads = 4 ;
3434
3535 cv::resize (image, image, cv::Size (480 , 360 ));
36- // image = ~image;
3736 cv::imshow (" InputImage for CNN" , image);
3837 image.convertTo (image, CV_32FC1, 1.0 / 255 );
39- // cv::waitKey(0);
40- // return 0;
38+
4139 // TFLite
4240 std::unique_ptr<tflite::FlatBufferModel> model = tflite::FlatBufferModel::BuildFromFile (MODEL_FILENAME);
4341 TFLITE_MINIMAL_CHECK (model != nullptr );
@@ -66,37 +64,25 @@ int main()
6664 std::cout << " input shape: " << input_string_stream.str () << std::endl;
6765 std::cout << " input array size: " << input_array_size << std::endl;
6866 printf (" === Got model input size ===\n " );
69- cv::waitKey (0 );
70- // return 0;
7167
7268 // Allocate tensor buffers.
7369 interpreter->SetNumThreads (num_of_threads);
7470 TFLITE_MINIMAL_CHECK (interpreter->AllocateTensors () == kTfLiteOk );
7571 printf (" === Pre-invoke Interpreter State ===\n " );
7672 tflite::PrintInterpreterState (interpreter.get ());
77- cv::waitKey (0 );
78- // return 0;
7973
8074 // Set data to input tensor
81- // float* input = interpreter->typed_input_tensor<float>(0);
75+ float * input = interpreter->typed_input_tensor <float >(0 );
8276 // memcpy(input, image.reshape(0, 1).data, sizeof(float) * 1 * 360 * 480 * 3);
83- // memcpy(input, image.data, sizeof(float) * input_array_size);
84-
85- uint8_t * input = interpreter->typed_input_tensor <uint8_t >(0 );
86- std::vector<uint8_t > input_data (image.data ,
87- image.data + (image.cols * image.rows * image.elemSize ()));
88- memcpy (input, input_data.data (), input_data.size ());
89-
77+ memcpy (input, image.data , sizeof (float ) * input_array_size);
9078 printf (" \n\n === MEM copied ===\n " );
91- cv::waitKey (0 );
9279
9380 // Run inference
9481 printf (" \n\n === Pre-invoke Interpreter State ===\n " );
9582 TFLITE_MINIMAL_CHECK (interpreter->Invoke () == kTfLiteOk );
9683 printf (" \n\n === Post-invoke Interpreter State ===\n " );
9784 tflite::PrintInterpreterState (interpreter.get ());
98- // cv::waitKey(0);
99- // return 0;
85+
10086 // Get data from output tensor
10187 float * probs = interpreter->typed_output_tensor <float >(0 );
10288 for (int i = 0 ; i < 10 ; i++) {
0 commit comments