Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tensor manipulations #342

Open
FlorianThaler opened this issue Mar 13, 2023 · 9 comments
Open

Tensor manipulations #342

FlorianThaler opened this issue Mar 13, 2023 · 9 comments

Comments

@FlorianThaler
Copy link

Hello.

I am searching for a possibility to transform a tensor (resulting from a call like vector<Tensor*> y = model->predict({x});_) into a std::vector of doubles. On the doc page I was not able to find a built-in function incorporating this manipulation. Is there a possibility to do that?

BR, Florian

@jonandergomez
Copy link
Contributor

Hello Florian,

Could you provide a couple of examples for the resulting object you are asking for using different shapes of the tensors contained in vector<Tensor *>?

Best Regards,

Jon

@FlorianThaler
Copy link
Author

Hello Jon.

Actually what I would like to do something like that
[...]
model_ = import_net_from_onnx_file(params.modelPath);
eddl::build(model_);
[...]
Tensor* x = new Tensor({x1, x2, x3, x4, x5}, {1, 5});
vector<Tensor*> y = model_->predict({x});

vector<double> weights;
weights = y.to_vector();                                  <<< **this is where I am stuck right now**
std::discrete_distribution<> d(weights.begin(), weights.end());
std::random_device rd;
auto ctrl_idx = d(rd);
[...]

BR, Florian

@RParedesPalacios
Copy link
Contributor

Hi, i have just implemented a new function: to_std(), an example:

t1 = Tensor::ones({5, 1});
std::vector vf=t1->to_std();

The result is a std_vector that maps the same memory of the tensor. Obviously the tensor could have several dimensions but std_vector is just a vector but all the values are there in a row-wise order.

Rigth now is a std_vector of floats. If you need doubles then it would be different since internal tensor pointer (and values) is a float pointer. But just try with this solution and let us know.

@FlorianThaler
Copy link
Author

Thanks a lot. I'll try.

BR, Florian

@jonandergomez
Copy link
Contributor

Hi Florian,

Just one additional question, do you download the master branch and compile the EDDL from the source code? Or do you need us to release a new version with this newly added feature?

Regards,

Jon

@FlorianThaler
Copy link
Author

Hi Jon,

so far we used build our docker container using one of your releases (by calling wget https://github.com/deephealthproject/eddl/archive/refs/tags/v1.1b.tar.gz). The best for us would be if you could provide another release - then rebuilding our container should be easy.

BR, Florian

@jonandergomez
Copy link
Contributor

I will do it asap and notify you, but you have to use a new tag.

@jonandergomez
Copy link
Contributor

Hi again,

@FlorianThaler you can now check the new tag with the new feature: https://github.com/deephealthproject/eddl/archive/refs/tags/v1.2b.tar.gz

Regards,

Jon

@FlorianThaler
Copy link
Author

Great, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants