I need to extract data from any middle layer. I need it for making comparing images, the idea is that if the model recognizes a cat it would check if that image of a cat matches the previous images of cats.
I have done the following:
model = YOLO("yolov8s")
del model.model.model[-1]
This way I am deleting the final layer, but I can't extract data from it. When I call the predict method I get the following:
File "\Lib\site-packages\ultralytics\utils\ops.py", line 219, in non_max_suppression
x = x[xc[xi]] # confidence
~^^^^^^^^
IndexError: The shape of the mask [12, 20] at index 0 does not match the shape of the indexed tensor [512, 20, 12] at index 0
What can I do differently to get the data? It would be better not create a model and delete the final layer( or x amount) because I still need the final result.