How to extract sample data from pb files?
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 9.8k
- Forks
- 1.6k
- PR merge metrics
- No merged PRs in 30d
Description
Ask a Question
Question
Hello, I tried MNIST Handwritten digit recognition in Java( and Scala).
I guessed test_dataset_0/input_0.pb contains sample data of type float array, but I didn't know/couldn't found how to extract that data from Java program. Thus, I attempted to decode input_0.pb using protoc.
After decoding raw input_0.pb file using protoc, I found there are key value pairs, one of which has 9 as key and quite long string as value, which seems to be encoded sample data of float array.
cat input_0.pb | protoc --decode_raw
1: 1
1: 1
1: 28
1: 28
2: 1
9: "\000\000\000\000\000\000\000\000\000\000\000\00........
Then, I found UnknownFieldSet in com.google.protobuf package.
I managed to extract sample data from pb file in the following way.
val result = ArrayBuilder.ofFloat()
val f = UnknownFieldSet
.parseFrom(
Files.readAllBytes(Path.of("./mnist/test_data_set_0/input_0.pb"))
)
.getField(9)
val buf = f.getLengthDelimitedList().get(0).asReadOnlyByteBuffer()
val cis = CodedInputStream.newInstance(buf)
while (!cis.isAtEnd) {
result.addOne(cis.readFloat())
}
result.result().toList
// List(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 3.0, 0.0, 0.0, 4.0, 2.0, 0.0, 11.0, 0.0, 0.0, 14.0, 1.0, 0.0, 19.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 12.0, 0.0, 0.0, 7.0, 0.0, 1.0, 10.0, 0.0, 2.0, 2.0, 16.0, 0.0, 3.0, 3.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 7.0, 8.0, 0.0, 8.0, 0.0, 0.0, 8.0, 0.0, 0.0, 19.0, 0.0, 0.0, 1.0, 21.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 11.0, 0.0, 0.0, 10.0, 3.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 13.0, 0.0, 15.0, 10.0, 26.0, 34.0, 17.0, 77.0, 181.0, 178.0, 35.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 150.0, 254.0, 250.0, 251.0, 243
result.result().toList.length
// => 784
Is this right way to extract sample data from pb file or is there better way to do this?
Further information
Relevant Area (e.g. model usage, backend, best practices, pre-/post- processing, converters):
model usage, best practives
Is this issue related to a specific model?
Model name (e.g. mnist): MNIST Handwritten digit recognition
Model opset (e.g. 7):
Notes
Any additional information, code snippets.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked MNIST model page and its test_data_set_0/input_0.pb file. Review the reported Java and Scala UnknownFieldSet/protoc approach, then document whether it is appropriate or identify the supported extraction method; done means a clear model-usage answer for this sample data.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, scala
- Domain
- documentation, machine-learning
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100