def apply_model_to_image_raw_bytes(img):
    # img = utils.decode_image_from_buf(raw)
    # fig = plt.figure(figsize=(7, 7))
    # plt.grid('off')
    # plt.axis('off')
    # plt.imshow(img)
    img = utils.crop_and_preprocess(img, (IMG_SIZE, IMG_SIZE), final_model.preprocess_for_model)
    # print(' '.join(generate_caption(img)[1:-1]))
    return str(' '.join(generate_caption(img)[1:-1]))
def apply_model_to_image_raw_bytes(raw, sample=False):
    img = utils.decode_image_from_buf(raw)
    plt.figure(figsize=(7, 7))
    plt.grid('off')
    plt.axis('off')
    plt.imshow(img)
    img = utils.crop_and_preprocess(img, (IMG_SIZE, IMG_SIZE), final_model.preprocess_for_model)
    print(' '.join(generate_caption(img, sample=sample)[1:-1]))
    plt.show()
Exemple #3
0
def apply_model_to_image_raw_bytes(raw, fname=None, do_save=False):
    img = utils.decode_image_from_buf(raw)
    fig = plt.figure(figsize=(7, 7))
    plt.grid('off')
    plt.axis('off')
    plt.imshow(img)
    img = utils.crop_and_preprocess(img, (IMG_SIZE, IMG_SIZE),
                                    final_model.preprocess_for_model)
    plt.title(' '.join(generate_caption(img)[1:-1]))
    if do_save:
        plt.savefig(fname)
    plt.show()
def apply_model_to_image_raw_bytes(raw):
    img = utils.decode_image_from_buf(raw)
    plt.figure(figsize=(7, 7))
    plt.grid('off')
    plt.axis('off')
    plt.imshow(img)
    img = utils.crop_and_preprocess(img, (IMG_SIZE, IMG_SIZE),
                                    generator_model.process_for_model)
    img = np.expand_dims(img, axis=0)
    title = generate_caption(img)[1:-1]
    plt.title(' '.join(title))
    plt.show()
def show_valid_example_series(val_img_fns, index_array):
    all_files = set(val_img_fns)
    found_files = list(
        filter(lambda x: x.filename.rsplit("/")[-1] in all_files, zf.filelist))
    #plt.figure()
    index = 1
    for row in range(index_array.shape[0]):
        for col in range(index_array.shape[1]):
            fn = found_files[index_array[row, col]]
            img = utils.decode_image_from_buf(zf.read(fn))
            subplot = plt.subplot(index_array.shape[0], index_array.shape[1],
                                  index)
            subplot.axis('off')
            subplot.grid('off')
            plt.imshow(img)
            img = utils.crop_and_preprocess(img, (IMG_SIZE, IMG_SIZE),
                                            generator_model.process_for_model)
            img_s = np.expand_dims(img, axis=0)
            title = generate_caption(img_s, sample=False)[1:-1]
            subplot.set_title(" ".join(title))
            index += 1
    plt.show()
Exemple #6
0
def apply_model_to_image_raw_bytes(raw):
    img = utils.decode_image_from_buf(raw)
    img = utils.crop_and_preprocess(img, (IMG_SIZE, IMG_SIZE),
                                    final_model.preprocess_for_model)
    print(' '.join(generate_caption(img)[1:-1]))
Exemple #7
0
def apply_model_to_image_raw_bytes_return_next_word_probs(raw, par_caption):
    img = utils.decode_image_from_buf(raw)
    img = utils.crop_and_preprocess(img, (IMG_SIZE, IMG_SIZE),
                                    final_model.preprocess_for_model)
    return generate_next_word_probs(img, par_caption)
Exemple #8
0
def apply_model_to_image(fname):
    img = imread(fname)[:,:,:3]
    img = utils.crop_and_preprocess(img, (IMG_SIZE, IMG_SIZE), final_model.preprocess_for_model)
    return (' '.join(generate_caption(img)[1:-1]))
def get_caption(img):
    img = utils.crop_and_preprocess(img, (IMG_SIZE, IMG_SIZE),
                                    generator_model.process_for_model)
    img = np.expand_dims(img, axis=0)
    return generate_caption(img)[1:-1]