Ejemplo n.º 1
0
def ShowKeypoints(keypoints, log_path, experiment_name, number_of_clusters,
                  dataset_name):

    dataset = Database(dataset_name, number_of_clusters)
    count = 0
    image_names = list(keypoints.keys())
    random.shuffle(image_names)

    fig, subplots = plt.subplots(8, 8, figsize=(15, 15))
    subplots = subplots.reshape(-1)
    fig.subplots_adjust(wspace=0, hspace=0)
    for s in subplots:
        s.set_axis_off()

    while count < 8 * 8:
        imagepoints = keypoints[image_names[count]]
        image = dataset.getimage_FAN(dataset, image_names[count])
        ax = subplots[count]
        ax.imshow(image)
        ax.scatter(4 * imagepoints[:, 0], 4 * imagepoints[:, 1])
        count += 1

    filename = GetLogsPath(experiment_name, log_path) / 'Keypoints.jpg'
    fig.savefig(filename)
    LogText(f"Keypoint images created in {filename}", experiment_name,
            log_path)
Ejemplo n.º 2
0
def ShowVisualRes(keypoints, log_path, experiment_name, number_of_clusters,
                  dataset_name):

    fig = plt.figure(figsize=(34, 55))
    gs1 = gridspec.GridSpec(13, 8)
    gs1.update(wspace=0.0, hspace=0.0)
    filenames = [
        k for k in keypoints.keys() if keypoints[k]['is_it_test_sample']
    ]
    filenames.sort()
    filenames = filenames[:13 * 8]
    dataset = Database(dataset_name, number_of_clusters, test=True)
    for i in range(len(filenames)):

        ax = plt.subplot(gs1[i])
        plt.axis('off')
        pointstoshow = keypoints[filenames[i]]['prediction']
        image = dataset.getimage_FAN(dataset, filenames[i])
        ax.imshow(image)
        colors = [
            Utils.colorlist[int(i)] for i in np.arange(len(pointstoshow))
        ]
        ax.scatter(pointstoshow[:, 0],
                   pointstoshow[:, 1],
                   s=400,
                   c=colors,
                   marker='P',
                   edgecolors='black',
                   linewidths=0.3)
    fig.show()

    filename = GetLogsPath(experiment_name, log_path) / 'Step2.jpg'
    fig.savefig(filename)

    LogText(f"Step2 results created in {filename}", experiment_name, log_path)
Ejemplo n.º 3
0
def ShowClusters(keypoints, log_path, experiment_name, number_of_clusters,
                 dataset_name):
    dataset = Database(dataset_name, number_of_clusters)

    image_names = list(keypoints.keys())
    random.shuffle(image_names)

    for cluster_number in range(number_of_clusters):

        counter_figureimages = 0
        counter_datasetimages = 0

        fig, subplots = plt.subplots(8, 8, figsize=(15, 15))
        subplots = subplots.reshape(-1)
        fig.subplots_adjust(wspace=0, hspace=0)

        for s in subplots:
            s.set_axis_off()

        while counter_figureimages < 64:

            #for the case where cluster has less than 64 instances
            if (counter_datasetimages > len(keypoints) - 1):
                filename = GetLogsPath(
                    experiment_name, log_path) / f'Cluster{cluster_number}.jpg'
                fig.savefig(filename)
                break

            imagename = image_names[counter_datasetimages]
            imagepoints = keypoints[imagename]

            #if cluster exists in image
            if (sum(imagepoints[:, 2] == cluster_number) > 0):
                image = dataset.getimage_FAN(dataset, imagename)
                ax = subplots[counter_figureimages]
                ax.imshow(image)
                ax.scatter(
                    4 * imagepoints[imagepoints[:, 2] == cluster_number, 0],
                    4 * imagepoints[imagepoints[:, 2] == cluster_number, 1])
                counter_figureimages += 1

            counter_datasetimages += 1

        filename = GetLogsPath(experiment_name,
                               log_path) / f'Cluster{cluster_number}.jpg'
        fig.savefig(filename)
        LogText(f"Cluster images created in {filename}", experiment_name,
                log_path)