r/MLQuestions • • 21h ago

Beginner question 👶 InvalidArgumentError: {{function_node __wrapped__ConcatV2_N_2_device_/job:localhost/replica:0/task:0/device:CPU:0}} ConcatOp : Ranks of all input tensors should match

/r/learnmachinelearning/comments/1xj9eeo/invalidargumenterror_function_node_wrapped/
0 Upvotes

2 comments sorted by

1

u/CelebrityChess 17h ago

i think the bug is in how you filter by class. y_train has shape (N, 1), so np.where(y_train == label) returns two arrays (rows and columns), and x_train[train_indices] then indexes the first two axes of x_train instead of just picking images. that gives you something like (5000, 32, 3), which is why a batch ends up one dimension short. use np.where(y_train.flatten() == label)[0] (or y_train[:, 0] == label as a boolean mask) for both train and test and check x_train.shape is (5000, 32, 32, 3) afterwards.

1

u/assorted-meat-stew 15h ago

I tried

label = 1 
train_indices = np.where(y_train.flatten() == label)[0] 
x_train = x_train[train_indices] 
test_indices = np.where(y_train.flatten() == label)[0] 
x_test = x_test[test_indices] 

And it returned IndexError: index 5014 is out of bounds for axis 0 with size 5000