deephealthproject / eddl

European Distributed Deep Learning (EDDL) library. A general-purpose library initially developed to cover deep learning needs in healthcare use cases within the DeepHealth project.
https://deephealthproject.github.io/eddl/
MIT License
34 stars 10 forks source link

Tensor manipulations #342

Open FlorianThaler opened 1 year ago

FlorianThaler commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Hello Jon.

Actually what I would like to do something like that [...] model_ = import_net_from_onnxfile(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 commented 1 year ago

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 commented 1 year ago

Thanks a lot. I'll try.

BR, Florian

jonandergomez commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

jonandergomez commented 1 year ago

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 commented 1 year ago

Great, thanks.