Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Loading ExtraFilesMap in Java?

See original GitHub issue


When saving a trained model using Pytorch, extra information can be added in Python or C++ using an ExtraFilesMap object. In Python this extra metadata can be extracted from a saved model e.g. via

# load the jit model and associated settings. 
extra_files = torch._C.ExtraFilesMap()
extra_files['dataOpts'] = ''
model = torch.jit.load(filepath_model, _extra_files=extra_files)

Using djl, a trained model can be loaded in Java, however, however, there does not appear to be any method to extract the ExtraFileMap information? I’ve spent some time trying to find a solution with no luck. Am I missing something - is this possible using djl?

If not, can we bump this to a feature request. It’s very useful having metadata such as this stored with the model.

Thanks for any help!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

lanking520commented, Nov 16, 2020

@macster110, please feel free to raise a PR to fix it 😃

lanking520commented, Nov 13, 2020

Ok, I optimized our import procedure. You will be able to fetch these information through:

Criteria<Image, Classifications> criteria = Criteria.builder()
  .setTypes(Image.class, Classifications.class)
  .optOption("extraFiles", "dataOpts")  // <- pass in here 
                 .setPipeline(new Pipeline()
                              .add(new Resize(224, 224))
                              .add(new ToTensor()))

ZooModel<Image, Classifications> model = ModelZoo.load(criteria);
model.getProperty("dataOpts"); // String representation of your dictionary

I tested with the model you have provided and it is working now. You can get the SNAPSHOT version and use it today. We have nightly snapshot published to maven everyday.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Loading ExtraFilesMap in Java? · Issue #312 - GitHub
Question When saving a trained model using Pytorch, extra information can be added in Python or C++ using an ExtraFilesMap object.
Read more >
How should I load files into my Java application?
The short answer. Use one of these two methods: Class.getResource(String) · Class.getResourceAsStream(String). For example:
Read more >
How to Save/Load Data with Text File (1/2) - Java Extra 15
Previous: this video, I'll explain how to save/ load your game by using a ...
Read more >
Different ways of Reading a text file in Java - GeeksforGeeks
Methods: Using BufferedReader class; Using Scanner class; Using File Reader class; Reading the whole file in a List; Read a text file as...
Read more >
How the JVM Locates, Loads, and Runs Libraries - Oracle Blogs
In this article, I explain the Java class-loading mechanism in detail and how it works. I also explain how classes are found in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found