pytorch / examples

A set of examples around pytorch in Vision, Text, Reinforcement Learning, etc.
https://pytorch.org/examples
BSD 3-Clause "New" or "Revised" License
22.3k stars 9.53k forks source link

No matching function call error in custom_dataset example #680

Open blgnksy opened 4 years ago

blgnksy commented 4 years ago

Hi, An error occurs when attempting to compile the sample code in line push_back(Functional(torch::log_softmax, 1, torch::nullopt));

And the error is

error: no matching function for call to 'torch::nn::Functional::Functional(<unresolved overloaded function type>, int, const c10::nullopt_t&)'

Am I missing something? I have used the same code in example.

smartnet-club commented 4 years ago

The problem described here

The fast solution - specify exact type of overloaded function passed to Functional:

push_back(Functional(static_cast<torch::Tensor(&)(const torch::Tensor&, int64_t, torch::optional<torch::ScalarType> )>(torch::log_softmax), 1, torch::nullopt));

deepali-c commented 4 years ago

@soumith, @ShahriarSS, the above solution resolves this issue. Do you think this can be added as fix to the example?

ShahriarRezghi commented 4 years ago

@deepali-c The last time we were working on structures for functions like log_softmax to replace torch::nn::Functional's. I think they should be used here.

msaroufim commented 2 years ago

@smartnet-club would you like to contribute the fix?