amazon-science / patchcore-inspection

Apache License 2.0
691 stars 142 forks source link

ValueError: all input arrays must have the same shape in metrics.py (Training with new dataset) #89

Open R-Ayanami opened 8 months ago

R-Ayanami commented 8 months ago

Thank you for your kind tutorial and framework. I'm trying to create a new model with my dataset, but "ValueError: all input arrays must have the same shape" occurs in metrics.py. I printed out the output of that part, and I found the input list to np.stack is incorrect. Some lists have 1 element and others have 3 elements. The number of former lists is same as "good" label data. Maybe I mistaked around this part. How can I fix this problem?

Fritzyuan commented 7 months ago

Hello! I have the same problem so I was wondering how did you solve it?

R-Ayanami commented 7 months ago

I thought the metrics.py outputs the zero matrices, so I changed the shape at the point where error is occured. I added following part in compute_pixelwise_retrieval_metrics() of metrics.py, and the model training has been started:

if isinstance(ground_truth_masks, list):  
    for i in range(len(ground_truth_masks)):
        if len(ground_truth_masks[i]) == 3:
            ground_truth_masks[i] = [ground_truth_masks[i][0]]

This is just a quick fix, so the discussion about metrics.py will help you, I think. And accutually, I want to know the correct solution about this problem :-)

MarcSaghir commented 6 months ago

Hey, I had a similar issue when trying to train on my own dataset. The masks of the mvtec dataset are grayscale images, whereas the masks I created by myself had 3 channels/were RGB images. You have to save your masks as grayscale images aswell, and this error shouldn't occurr anymore.