Package org.pytorch
Class Module
- java.lang.Object
-
- org.pytorch.Module
-
public class Module extends java.lang.ObjectJava wrapper for torch::jit::Module.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddestroy()Explicitly destroys the native torch::jit::Module.IValueforward(IValue... inputs)Runs the 'forward' method of this module with the specified arguments.static Moduleload(java.lang.String modelPath)Loads a serialized TorchScript module from the specified path on the disk to run on CPU.static Moduleload(java.lang.String modelPath, java.util.Map<java.lang.String,java.lang.String> extraFiles, Device device)Loads a serialized TorchScript module from the specified path on the disk to run on specified device.IValuerunMethod(java.lang.String methodName, IValue... inputs)Runs the specified method of this module with the specified arguments.
-
-
-
Method Detail
-
load
public static Module load(java.lang.String modelPath, java.util.Map<java.lang.String,java.lang.String> extraFiles, Device device)
Loads a serialized TorchScript module from the specified path on the disk to run on specified device.
-
load
public static Module load(java.lang.String modelPath)
Loads a serialized TorchScript module from the specified path on the disk to run on CPU.- Parameters:
modelPath- path to file that contains the serialized TorchScript module.- Returns:
- new
Moduleobject which owns torch::jit::Module.
-
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.
-
runMethod
public IValue runMethod(java.lang.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.
-
destroy
public void destroy()
Explicitly destroys the native torch::jit::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 callingdestroycan free memory more quickly. SeeHybridData.resetNative().
-
-