diff --git a/juice/src/layer.rs b/juice/src/layer.rs index 0fcedf3bf..f27aeb553 100644 --- a/juice/src/layer.rs +++ b/juice/src/layer.rs @@ -545,10 +545,22 @@ impl Layer { // reshape input tensor to the reshaped shape let old_shape = self.input_blobs_data[input_i].read().unwrap().desc().clone(); if old_shape.size() != reshaped_shape.size() { - panic!( - "Input Shape Mismatch\nExpected {:?}\nActual {:?}", - reshaped_shape, old_shape + eprintln!( + "Input Shape Mismatch at layer {}\nLayer has input shape {:?}\nInput given has shape {:?}", + self.name, reshaped_shape, old_shape ); + if reshaped_shape[1..] == old_shape[1..] { + eprintln!("This may be a batch size error"); + eprintln!("Expected batch size {} but got batch size {}.", reshaped_shape[0], old_shape[0]); + } + else if reshaped_shape[1..] == old_shape { + eprintln!("This may be a batch size error"); + eprintln!("Expected batch size {} but got batch size {}.", reshaped_shape[0], 1); + } + if reshaped_shape == old_shape[1..] { + eprintln!("You may have forgotten to specify a batch size in your model input."); + } + panic!(); } self.input_blobs_data[input_i] .write() diff --git a/juice/src/layers/common/linear.rs b/juice/src/layers/common/linear.rs index 38d90b993..45cf18b8a 100644 --- a/juice/src/layers/common/linear.rs +++ b/juice/src/layers/common/linear.rs @@ -86,6 +86,9 @@ impl> ILayer for Linear { output_data: &mut Vec>>, output_gradient: &mut Vec>>, ) { + if input_data.len() == 0 { + panic!("Linear layer expected input, but none was given."); + } let input = input_data[0].read().unwrap(); let batch_size = input.desc()[0]; // reshape top diff --git a/juice/src/layers/container/sequential.rs b/juice/src/layers/container/sequential.rs index 1808f8b83..36238b116 100644 --- a/juice/src/layers/container/sequential.rs +++ b/juice/src/layers/container/sequential.rs @@ -293,6 +293,9 @@ impl + 'static> ILayer for Sequential { output_data: &mut [ArcLock>], ) { for layer in &self.layers { + if layer.borrow().input_blob_names.len() < input_data.len() { + panic!("Layer {} expected {} input(s) but got {}.", layer.borrow().name, layer.borrow().input_blob_names.len(), input_data.len()); + } for (i, (input, input_name)) in input_data.iter().zip(self.input_tensor_names.iter()).enumerate() { if &layer.borrow().input_blob_names[i] == input_name { layer.borrow_mut().input_blobs_data[i] = input.clone();