Почему моя сиамская модель не работает с проверочными данными?Python

Программы на Python
Ответить
Anonymous
 Почему моя сиамская модель не работает с проверочными данными?

Сообщение Anonymous »

Моя модель работала раньше и давала хорошие прогнозы. Однако теперь я пробую это, и он не может распознать сходство между изображениями, как должно. Помогите, пожалуйста, с этой проблемой.

Код: Выделить всё

# Save weights
siamese_model.save('siamesemodel.h5')

# Load the model
model = tf.keras.models.load_model(
'siamesemodel.h5',
custom_objects={'L1Dist': L1Dist, 'BinaryCrossentropy': tf.losses.BinaryCrossentropy}
)

# Verification Function
def verify(model, detection_threshold, verification_threshold):
# Build results array
results = []
for image in os.listdir(os.path.join('application_data', 'verification_images')):
input_img = preprocess(os.path.join('application_data', 'input_image', 'input_image.jpg'))
validation_img = preprocess(os.path.join('application_data', 'verification_images', image))

result = model.predict(list(np.expand_dims([input_img, validation_img], axis=1)))
results.append(result)

# Detection Threshold: Metric above which prediction is considered positive
detection = np.sum(np.array(results) > detection_threshold)

Код: Выделить всё

    # Verification Threshold: Proportion of positive predictions / total positive samples
verification = detection / len(os.listdir(os.path.join('application_data', 'verification_images')))
verified = verification > verification_threshold

return results, verified

cap = cv2.VideoCapture(0)
while cap.isOpened():
ret, frame = cap.read()
frame = frame[120:120+250, 200:200+250, :]

cv2.imshow('Verification', frame)

# Verification trigger
if cv2.waitKey(10) & 0xFF == ord('v'):
# Save input image to input_image folder
cv2.imwrite(os.path.join('application_data', 'input_image', 'input_image.jpg'), frame)
# Run verification
results, verified = verify(model, 0.5, 0.5)
print(verified)

if cv2.waitKey(10) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
Результаты печати дают следующее:

Код: Выделить всё

[array([[9.938484e-09]], dtype=float32),
array([[0.00011181]], dtype=float32),
array([[4.0544733e-06]], dtype=float32),
array([[3.6490118e-07]], dtype=float32),
array([[1.779369e-07]], dtype=float32),
array([[0.15224604]], dtype=float32),
array([[2.0296879e-05]], dtype=float32),
array([[7.9831276e-05]], dtype=float32),
array([[2.3284203e-05]], dtype=float32),
array([[8.0619594e-07]], dtype=float32),
array([[1.0691416e-06]], dtype=float32),
array([[1.9231505e-08]], dtype=float32),
array([[2.243531e-05]], dtype=float32),
array([[6.483703e-07]], dtype=float32),
array([[6.656185e-07]], dtype=float32),
array([[4.8954314e-07]], dtype=float32),
array([[9.550116e-08]], dtype=float32),
array([[1.305056e-07]], dtype=float32),
array([[4.187218e-09]], dtype=float32),
array([[3.8443446e-08]], dtype=float32),
array([[5.9630083e-09]], dtype=float32),
array([[1.1699244e-06]], dtype=float32),
Я знаю, что с сохранением модели нет проблем, потому что, когда я тестировал перезагруженную модель и исходную модель на исходных входных данных, они имели одинаковые выходные данные.Для заданных входных данных, которые оба раза представляют собой кадр со мной, большинство результатов должны быть значительно выше 0,5. Я не могу понять, что пошло не так. Кстати, этот код в основном взят из учебника YT:

Подробнее здесь: https://stackoverflow.com/questions/791 ... ation-data
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»