This sample project demonstrates swift / python interoperability with pyTorch.

  
      
      GitHub
  
  
    

johndpope/SwiftTorch 14

🏗PyTorch + Swift mashup. Contribute to johndpope/SwiftTorch development by creating an account on GitHub.


  
  
    
    
  
  


The swift code (leveraging swift for tensorflow toolchain) - can interoperate with an individual python class.
//swift
let neuralNet = Python.import("NeuralNet").NeuralNet() //  load local NeuralNet.py

// NeuralNet.py 


pytorch.png704×882 80.2 KB

Small print
N.B. you have to hard code the customClassPath for the app to where you’ve saved files to correctly load the python file.
The project is using 2,7 with miniconda - but it’s now possible to use python 3 in latest toolchain
see -
PythonLibrary.useVersion(2, 7)