linusdm
Elixir/Nx/Axon equivalents of PyTorch code
Hello Nx community! ![]()
I’m here as a noob in the field of AI (and python), trying to accomplish a task with my favourite language. I’d like to use an exported ONNX model (exported from a torch model, built in python, which I can load from the filesystem). Someone before me has written some python code to execute the torch model, which I would like to do in elixir. The gist boils down to the following:
import pandas as pd
import numpy as np
import torch
model = torch.load('/path/to/model.torch', map_location=torch.device('cpu'))
pred = {}
for index, data_frame in some_list_of_data_frames:
feats = torch.from_numpy(np.array(data_frame, dtype=np.float32))
with torch.no_grad():
pred[index] = model.forward(feats.unsqueeze(0)).detach().cpu().numpy()[0]
result = pd.DataFrame.from_dict(pred, orient="index", columns=["some", "set", "of", "columns"])
The data frames are built somehow, but that’s for later (with explorer, I suppose). I’d like to know what a comparable elixir implementation would be, if at all possible. I manage to load the ONNX model with the axon_onnx lib, which spits out the axon model and a map of params, which is a start. But then I don’t really know how to mimic the torch.from_numpy(), torch.no_grad(), model.forward(...).detach().cpu().numpy() and pd.DataFrame.from_dict(...). If anyone has tips to share, I’d be very grateful ![]()
Most Liked
josevalim
NickGnd
Hey @linusdm ![]()
A bit late, but in case you are still looking for something…
I have a similar need for creating a histogram where I can specify the bins wherein I can sum values, to get to a tensor with well structured series data. Something like this numpy
histogramfunction: numpy.histogram — NumPy v1.23 Manual
I think Explorer might be of help here, have you seen Explorer.Series.cut/3? Is not as fancy as numpy.histogram, but for “basic” histogram creation works fine ![]()
Cheers ![]()
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









