GabrielJadderson / SimplePyTorch

UE4 Plugin to execute trained PyTorch modules

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SimplePyTorch

UE4 Plugin to execute already trained PyTorch modules.

Packaging

  1. Download PyTorch C++ distributions.
  2. Copy DLLs from runtime lib directory to SimplePyTorch/Source/ThirdParty/pytorch/Binaries/Win64:

asmjit.dll, c10.dll, caffe2_detectron_ops.dll, caffe2_module_test_dynamic.dll, fbgemm.dll, fbjni.dll, libiomp5md.dll, libiompstubs5md.dll, torch.dll, torch_cpu.dll, torch_global_deps.dll, uv.dll.

  1. Copy the plugin to [your UE4 project]/Plugins directory and recompile.

Usage

// Create module UObject

auto TorchModule = USimpleTorchModule::CreateSimpleTorchModule(this);

// Load script model

TorchModule->LoadTorchScriptModel(ModelFileFile);

// Fill input tensor

FSimpleTorchTensor Inputs = FSimpleTorchTensor( { 1, 2 } );

Inputs[0][0] = 1.f; Inputs[0][1] = 1.f;

// call model method

FSimpleTorchTensor Outputs = FSimpleTorchTensor( { 1 } );

TorchModule->ExecuteModelMethod("forward", Inputs, Outputs);

// read result

UE_LOG(LogTemp, Log, TEXT("Returned value: %f"), Outputs[0].Item());

About

UE4 Plugin to execute trained PyTorch modules


Languages

Language:C++ 90.0%Language:C# 10.0%