Shortcuts

Module

public class Module

Java wrapper for torch::jit::script::Module.

Methods

destroy

public void destroy()

Explicitly destroys the native torch::jit::script::Module. Calling this method is not required, as the native object will be destroyed when this object is garbage-collected. However, the timing of garbage collection is not guaranteed, so proactively calling destroy can free memory more quickly. See com.facebook.jni.HybridData.resetNative.

forward

public IValue forward(IValue... inputs)

Runs the ‘forward’ method of this module with the specified arguments.

Parameters
  • inputs – arguments for the TorchScript module’s ‘forward’ method.

Returns

return value from the ‘forward’ method.

load

public static Module load(String modelPath)

Loads a serialized TorchScript module from the specified path on the disk.

Parameters
  • modelPath – path to file that contains the serialized TorchScript module.

Returns

new org.pytorch.Module object which owns torch::jit::script::Module.

runMethod

public IValue runMethod(String methodName, IValue... inputs)

Runs the specified method of this module with the specified arguments.

Parameters
  • methodName – name of the TorchScript method to run.

  • inputs – arguments that will be passed to TorchScript method.

Returns

return value from the method.

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources