MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / main

Function main

tensorflow/examples/speech_commands/label_wav.cc:101–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99} // namespace
100
101int main(int argc, char* argv[]) {
102 string wav = "";
103 string graph = "";
104 string labels = "";
105 string input_name = "wav_data";
106 string output_name = "labels_softmax";
107 int32 how_many_labels = 3;
108 std::vector<Flag> flag_list = {
109 Flag("wav", &wav, "audio file to be identified"),
110 Flag("graph", &graph, "model to be executed"),
111 Flag("labels", &labels, "path to file containing labels"),
112 Flag("input_name", &input_name, "name of input node in model"),
113 Flag("output_name", &output_name, "name of output node in model"),
114 Flag("how_many_labels", &how_many_labels, "number of results to show"),
115 };
116 string usage = tensorflow::Flags::Usage(argv[0], flag_list);
117 const bool parse_result = tensorflow::Flags::Parse(&argc, argv, flag_list);
118 if (!parse_result) {
119 LOG(ERROR) << usage;
120 return -1;
121 }
122
123 // We need to call this to set up global state for TensorFlow.
124 tensorflow::port::InitMain(argv[0], &argc, &argv);
125 if (argc > 1) {
126 LOG(ERROR) << "Unknown argument " << argv[1] << "\n" << usage;
127 return -1;
128 }
129
130 // First we load and initialize the model.
131 std::unique_ptr<tensorflow::Session> session;
132 Status load_graph_status = LoadGraph(graph, &session);
133 if (!load_graph_status.ok()) {
134 LOG(ERROR) << load_graph_status;
135 return -1;
136 }
137
138 std::vector<string> labels_list;
139 Status read_labels_status = ReadLabelsFile(labels, &labels_list);
140 if (!read_labels_status.ok()) {
141 LOG(ERROR) << read_labels_status;
142 return -1;
143 }
144
145 string wav_string;
146 Status read_wav_status = tensorflow::ReadFileToString(
147 tensorflow::Env::Default(), wav, &wav_string);
148 if (!read_wav_status.ok()) {
149 LOG(ERROR) << read_wav_status;
150 return -1;
151 }
152 Tensor wav_tensor(tensorflow::DT_STRING, tensorflow::TensorShape({}));
153 wav_tensor.scalar<tstring>()() = wav_string;
154
155 // Actually run the audio through the model.
156 std::vector<Tensor> outputs;
157 Status run_status =
158 session->Run({{input_name, wav_tensor}}, {output_name}, {}, &outputs);

Callers

nothing calls this directly

Calls 12

UsageFunction · 0.85
ParseFunction · 0.85
ReadFileToStringFunction · 0.85
DefaultFunction · 0.85
LoadGraphFunction · 0.70
ReadLabelsFileFunction · 0.70
GetTopLabelsFunction · 0.70
FlagClass · 0.50
InitMainFunction · 0.50
TensorShapeClass · 0.50
okMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected