예제 #1
0
파일: cnn.py 프로젝트: laranea/dupre
    def __init__(self) -> None:
        """
        Initialize a keras MobileNet model that is sliced at the last convolutional layer.
        Set the batch size for keras generators to be 64 samples. Set the input image size to (224, 224) for providing
        as input to MobileNet model.
        """
        from tensorflow.keras.applications.mobilenet import MobileNet, preprocess_input
        from imagededup.utils.data_generator import DataGenerator

        self.MobileNet = MobileNet
        self.preprocess_input = preprocess_input
        self.DataGenerator = DataGenerator

        self.target_size = (224, 224)
        self.batch_size = 64
        self.logger = return_logger(__name__, os.getcwd())
        self._build_model()
예제 #2
0
    def __init__(self, verbose: bool = True) -> None:
        """
        Initialize a keras MobileNet model that is sliced at the last convolutional layer.
        Set the batch size for keras generators to be 64 samples. Set the input image size to (224, 224) for providing
        as input to MobileNet model.

        Args:
            verbose: Display progress bar if True else disable it. Default value is True.
        """
        from tensorflow.keras.applications.mobilenet import MobileNet, preprocess_input
        from imagededup.utils.data_generator import DataGenerator

        self.MobileNet = MobileNet
        self.preprocess_input = preprocess_input
        self.DataGenerator = DataGenerator

        self.target_size = (224, 224)
        self.batch_size = 64
        self.logger = return_logger(__name__)
        self._build_model()
        self.verbose = 1 if verbose is True else 0
예제 #3
0
import os
import itertools
from typing import Dict

from imagededup.handlers.metrics.classification import classification_metrics
from imagededup.handlers.metrics.information_retrieval import (
    mean_metric,
    get_all_metrics,
)
from imagededup.utils.logger import return_logger

logger = return_logger(__name__, os.getcwd())


def _transpose_checker(mapping):
    """
    Check for the given dictionary that transpose (symmetric) relationship holds.

    Args:
        mapping: Dictionary representing a mapping of filenames to the list of respective duplicate filenames.
    """
    for key, val in mapping.items():
        # check for each value in the list if the key is present as its value
        for v in val:
            assert key in mapping[v], (
                f'Transpose relationship violated, file {key} not present as a duplicate for file {v} in the provided'
                f' mapping dictionary')


def _check_map_correctness(ground_truth_map: Dict, retrieved_map: Dict):
    """
예제 #4
0
import itertools
from typing import Dict, List, Tuple

import numpy as np

from sklearn.metrics import (
    classification_report,
    precision_score,
    recall_score,
    precision_recall_fscore_support,
)
from imagededup.utils.logger import return_logger

logger = return_logger(__name__)


def _get_unique_ordered_tuples(unique_tuples: List[Tuple]) -> List[Tuple]:
    """Sort each tuple given a list of tuples and retain only unique pairs regardless of order within the tuple.
    Eg: [(2, 1), (1, 2), (3, 4)]  becomes [(1, 2), (3, 4)]"""

    return list(set([tuple(sorted(i)) for i in unique_tuples]))


def _make_all_unique_possible_pairs(ground_truth_dict: Dict) -> List[Tuple]:
    """
    Given a ground truth dictionary, generate all possible unique image pairs (both negative and positive pairs).
    """
    # get all elements of the dictionary
    all_files = list(ground_truth_dict.keys())

    # make all possible pairs (remove pairs with same elements)