linusdm

linusdm

Hello Nx community! :wave:

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 :pray:

Showing Posts 1 to 4

josevalim

josevalim

Creator of Elixir

Maybe this guide is a good starting point: https://github.com/elixir-nx/axon/pull/227

linusdm

linusdm OP

Thanks for the reference! This gives me some insight on how to run the model. The gist is to run Axon.predict/4 on the input tensor.

As a follow-up question: to construct the input tensor I’d like to do a linear interpolation of series data, just like this numpy interp function: numpy.interp — NumPy v2.5 Manual
Is this in scope of Nx, or should I look elsewhere? I’m not finding anything related to linear interpolation right now (but maybe there are better terms to describe this problem, and I’m not looking for the right words).

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 histogram function: numpy.histogram — NumPy v2.5 Manual

As far as I understand these things are related to building and manipulating a tensor, and should be found around the Nx library. But correct me if I’m wrong, and if there are other libs that I should look into.

linusdm

linusdm OP

After thinking about it some more, I think I’m looking in the wrong space. The things I want to do are not something Nx would be able to help me (interpolating and aggregating in a histogram). I can’t expect all the numpy goodies to be available in Nx or Explorer. Numpy has a way bigger API surface.

In my specific case, I can roll my own transformations (which does involve enumerating all values, which is fine because my tensors are relatively small).

NickGnd

NickGnd

Hey @linusdm :wave:

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 histogram function: 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 :wink:

Cheers :v:

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews