示例#1
0
def show06():

    start_image_file = '000238.jpg'
    end_image_file = '000193.jpg'

    images, _ = data_flow.next()

    z_points = vae.encoder.predict(images)

    interpolated_images = []

    interpolated_images.append(images[0]) # Add the first selected image.

    factors = np.arange(0, 1, 0.1)

    for factor in factors:

        z = z_points[0] * (1 - factor) + z_points[1]  * factor
        img = vae.decoder.predict(np.array([z]))[0]
        interpolated_images.append(img)

    interpolated_images.append(images[1]) # Add the second selected image.

    num_interpolated_images = len(factors)

    viewer = Viewer(num_rows=1, num_cols=num_interpolated_images+2, width=num_interpolated_images+2, height=1)
    viewer.add_row(interpolated_images)
    viewer.show()
示例#2
0
def show03():

    viewer = Viewer(num_rows=3, num_cols=10, width=10, height=3)

    for i in range(3):
        z_points = np.random.normal(size=(10, vae.z_dim))
        generated_images = vae.decoder.predict(np.array(z_points))
        viewer.add_row(generated_images)

    viewer.show()
示例#3
0
def show05():

    z_avg_pos = np.zeros(shape=vae.z_dim, dtype='float32') # for the attribute with '+1'
    z_avg_neg = np.zeros(shape=vae.z_dim, dtype='float32') # for the attribute with '-1'

    z_count_pos = 0
    z_count_neg = 0

    while True:

        images, labels = data_flow.next()

        z_points = vae.encoder.predict(images)

        z_points_pos = z_points[labels== 1]
        z_points_neg = z_points[labels==-1]

        z_avg_pos += np.sum(z_points_pos, axis=0)
        z_avg_neg += np.sum(z_points_neg, axis=0)

        z_count_pos += len(z_points_pos)
        z_count_neg += len(z_points_neg)

        if z_count_pos > 2000: # 2000 points are enough to get the center.
            break;

    z_avg_pos = z_avg_pos / z_count_pos
    z_avg_neg = z_avg_neg / z_count_neg

    z_direction = z_avg_pos - z_avg_neg
    magnitude = np.linalg.norm(z_direction) # magnitude
    z_direction = z_direction / magnitude # normalization

    # Select the first five images from the next batch.
    images, _ = data_flow.next()[:5]

    z_points = vae.encoder.predict(images)

    z_scales = [-4, -3, -2, -1, 0, 1, 2, 3, 4]

    viewer = Viewer(num_rows=5, num_cols=9, width=9, height=5)

    for i in range(5):

        images = []

        for z_scale in z_scales:

            changed_z_point = z_points[i] + z_direction * z_scale
            changed_image = vae.decoder.predict(np.array([changed_z_point]))[0]
            images.append(changed_image)

        viewer.add_row(images)

    viewer.show()
示例#4
0
def show01():

    input_images, _ = data_flow.next() # Get the first batch.
    input_images = input_images[:10] # Select the first 10 images from it.

    # method 1
    #z_points = vae.encoder.predict(input_images)
    #reconstructed_images = vae.decoder.predict(z_points)
    #print(len(z_points)) = 10: # of inputs
    #print(z_points.shape) = (10, 200): (# of inputs, z_dim)

    # method 2
    output_images = vae.model.predict(input_images)

    viewer = Viewer(num_rows=2, num_cols=10, width=10, height=2)
    viewer.add_row(input_images)
    viewer.add_row(output_images)
    viewer.show()
示例#5
0
def show04():

    viewer = Viewer(num_rows=5, num_cols=10, width=10, height=5)

    for i in range(5):

        satisfied_images = []

        while True:

            images, labels = data_flow.next()

            for j in range(len(images)):
                if labels[j] == 1: # satisfied!
                    satisfied_images.append(images[j])

            if len(satisfied_images) > 10:
                break

        viewer.add_row(satisfied_images[:10]) # Show only the first 10 images in a column.

    viewer.show()
# iteration method 1 #
viewer = Viewer(num_rows=iterations, num_cols=batch_size, width=10, height=10)

for i in range(iterations):

    images, labels = [], []

    image, label = data_flow.next()

    for j in range(batch_size):
        images.append(image[j])
        labels.append(label[j])

    viewer.add_row(images, labels)

viewer.show()

######################
# iteration method 2 #
viewer = Viewer(num_rows=iterations, num_cols=batch_size, width=10, height=10)

for i, (image, label) in enumerate(data_flow):

    images, labels = [], []

    for j in range(batch_size):
        images.append(image[j])
        labels.append(label[j])

    viewer.add_row(images, labels)