Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions juice/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,10 +545,22 @@ impl<B: IBackend> Layer<B> {
// 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..] {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd make more sense to add an assert per dimension, and just fail with the first.

for dim in 0..5 {
     let old = old_shape[dim];
     let reshaped = reshaped__shape[dim];
     assert_eq!(old, reshpaed, "Dimension {dim} mismatches {old} != {reshaped}"); 
}
unreachable!("If the total size is not equal, one dimension mismatch must exist. qed");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it this way to catch some errors with mismatched batch sizes to make it a bit more clear.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should always show the full dimensions as well. That way it stays clear where it could originate from your code. These errors can arise from rather deep inside the code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that my recent commit should have done this.

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()
Expand Down
3 changes: 3 additions & 0 deletions juice/src/layers/common/linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ impl<B: IBackend + LayerOps<f32>> ILayer<B> for Linear {
output_data: &mut Vec<ArcLock<SharedTensor<f32>>>,
output_gradient: &mut Vec<ArcLock<SharedTensor<f32>>>,
) {
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
Expand Down
3 changes: 3 additions & 0 deletions juice/src/layers/container/sequential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ impl<B: IBackend + LayerOps<f32> + 'static> ILayer<B> for Sequential<B> {
output_data: &mut [ArcLock<SharedTensor<f32>>],
) {
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());
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃憤

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();
Expand Down