Closed quietlychris closed 4 years ago
@quietlychris
Oh sorry, that's a newly introduced bug in refactoring of examples... dataset code in example is correct for multi-layer perceptron example, but is not for convnet. That should be:
// x_train and x_test should be 4D (not 2D)
let x_train = as_arr(ndarray::IxDyn(&[num_image_train, 1, 28, 28]), train_x).unwrap();
let x_test = as_arr(ndarray::IxDyn(&[num_image_test, 1, 28, 28]), test_x).unwrap();
I'll fix it later!
Thanks for getting back to me so quickly! That's great to hear. I applied that fix to the mnist_data.rs
file, and it definitely solved the cnn_mnist
example, although I'm still seeing the same problem on the lstm_lm
one, which I think ends up being due to a mismatch in the dimensions of the gradients
and feed
objects during the graph.eval()
step in the test helper module. I haven't had time to put together a fix for it, but if I find one, I might submit a pull request.
Just as an aside, huge thanks for putting this crate together. I've been playing around with doing some machine learning in Rust using only linear algebra in a proof-of-concept here, but I'm seriously considering re-writing it so that it's more or less an API wrapper around autograd
rather than continuing to re-invent the wheel, especially since I'm not sure I could match the quality of this code anyway.
Just as an update, I've been working on figuring out why this bug is appearing in the mlp_mnist
example after that fix is applied, and it definitely looks like the issue is the same one that has appeared in lstm_lm
.
The issue occurs because the
g.eval(update_ops, &[x.given(x_batch), y.given(y_batch)]);
line internally ends up calling the ops/dot_ops.rs
function compute()
which uses
let mut a = ctx
.input(0)
.into_dimensionality::<ndarray::Ix2>()
.expect("lhs input for MatMul must be 2D");
Print debugging successfully gets me through to just before this function is called, and then ends up panicing because trying to convert (from the default batch-size of 200) 4D object of shape ctx.input(0).shape() = [200, 1, 28, 28]
doesn't seem to work. I've tried other ndarray
functions like broadcast()
, but wasn't able to get any of them working.
The lstm_lm
example has a three-dimensional input shape of ctx.input(0).shape() = [2,1,4]
, and panics at exactly the same spot.
Comparatively in the cnn_mnist
example, the shape of ctx.input(0).shape() = [200, 3136]
seems to work with the two-dimensional requirement and doesn't panic as a result.
Any suggestions on where to look for a fix?
@quietlychris Sorry for the late reply!
I've been working on figuring out why this bug is appearing in the mlp_mnist example
This is because mlp_mnist requires 2D inputs while cnn_mnist does 4D.
I suggested to fix mnist_data.rs to return 4D, but 2D return value may more make because mnist is gray scale data (single channel) ...
So I think it's preferable to reshape the 2D input images to (batch, 1, 28, 28)
after this line using Array::into_shape
.
For lstm, it's a simple index-out-of-range bug in this process (i+2 exceeds the max sentence length).
Changing (0..max_sent)
to (0..max_sent-1)
should solve this problem!
While looking into these bugs, I found that weakness of this crate is its debuggability...
Fixed in v1.0.1 and master head.
Hi! I'm having some trouble with running a couple of the examples from your project. My process was the following:
which results in the following error. I've compiled it both with and without the
--features mkl
flag, and with and without the--release
flag, neither of which seems have any effect on these errors. As far as I can tell, they don't seem to be trace back to the same problem, but I may be mistaken. I'm runningrustc 1.46.0-nightly (feb3536eb 2020-06-09)
, on Pop!_OS 20.04 LTS, which closely mirrors Ubuntu. If it would be easier for me to open separate issues for each of these, I would be happy to do so.However, I am able to compile and run the
mlp_mnist
example without issue.When running
$ RUST_BACKTRACE=1 cargo run --example lstm_lm
, I get the following error: