Пример #1
0
def classify(image: PILImage, learner: Learner) -> Tuple[AnimalType, float]:
    with learner.no_bar():
        results = learner.predict(image)
    _, category, probabilities = results
    is_a_cat = category == 1
    animal_type = AnimalType.cat if is_a_cat else AnimalType.dog
    percent = np.round(100 * probabilities)
    return animal_type, percent[category]
Пример #2
0
def predict(pdf_tiles: list, learner: Learner):
    # Get predicted labels and confidences for the given image tiles
    predictions = [learner.predict(tile) for tile in pdf_tiles]
    labels = [prediction[0] for prediction in predictions]
    confidences = [
        float(prediction[2][prediction[1]].numpy())
        for prediction in predictions
    ]
    return labels, confidences