JakubSochor / BoxCars

Source code related to BoxCars publication
205 stars 67 forks source link

Trained Model fails in evaluation and single image classification #28

Open Libeiji opened 2 years ago

Libeiji commented 2 years ago

Hi Jakub,

I tried to train new ResNet50 model, and it seemed quite good on the result. ![Uploading Screenshot from 2022-08-24 10-05-51.png…]() However, when I tried to evaluate using python3 train_eval.py --eval path-to-model.h5 the evaluation result on 'test' part is bad Screenshot from 2022-08-24 10-20-35

Also when I tried to use the model to predict single image class, it also went bad. Here is my code for single image prediction.(quote some lines from your work) Where did I do wrong in this thanks!

from keras.models import load_model                          
from keras.preprocessing.image import load_img               
from keras.preprocessing.image import img_to_array           
from keras.applications.resnet50 import preprocess_input     
from keras.applications.resnet50 import decode_predictions   
import cv2           
import numpy as np   

path_to_model = ....
model= load_model(path_to_model)      
image = cv2.imread("027491_007.png")                          
image = cv2.resize(image,(224,224))                           
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)                
image = (image.astype(np.float32) - 116)/128.                 
x = np.empty([1] + list((224,224)) + [3], dtype=np.float32)   
x[0, ...] = image                                             

predict = model.predict(x);                                   
pred_idx = np.argmax(predict)                                 
print(predict,pred_idx)                                       
Libeiji commented 2 years ago

Screenshot from 2022-08-24 10-05-51 The training process is here