Given a list `examples`, write a text format representation. The file format is csv like with a simple repeated pattern. We would ike to use proto here, but we can't yet due to interfacing with the Android team using this format. Args: fp: File-like object to write to. examples: Ex
(fp, examples)
| 168 | |
| 169 | |
| 170 | def write_examples(fp, examples): |
| 171 | """Given a list `examples`, write a text format representation. |
| 172 | |
| 173 | The file format is csv like with a simple repeated pattern. We would ike |
| 174 | to use proto here, but we can't yet due to interfacing with the Android |
| 175 | team using this format. |
| 176 | |
| 177 | Args: |
| 178 | fp: File-like object to write to. |
| 179 | examples: Example dictionary consiting of keys "inputs" and "outputs" |
| 180 | """ |
| 181 | |
| 182 | def write_tensor(fp, x): |
| 183 | """Write tensor in file format supported by TFLITE example.""" |
| 184 | fp.write("dtype,%s\n" % x.dtype) |
| 185 | fp.write("shape," + ",".join(map(str, x.shape)) + "\n") |
| 186 | fp.write("values," + format_result(x) + "\n") |
| 187 | |
| 188 | fp.write("test_cases,%d\n" % len(examples)) |
| 189 | for example in examples: |
| 190 | fp.write("inputs,%d\n" % len(example["inputs"])) |
| 191 | for i in example["inputs"]: |
| 192 | write_tensor(fp, i) |
| 193 | fp.write("outputs,%d\n" % len(example["outputs"])) |
| 194 | for i in example["outputs"]: |
| 195 | write_tensor(fp, i) |
| 196 | |
| 197 | |
| 198 | def write_test_cases(fp, model_name, examples): |
no test coverage detected