예제 #1
0
def create_bottleneck(bottleneck_path, image_lists, label_name, index,
                      image_dir, category, sess, jpeg_data_tensor,
                      decoded_image_tensor, resized_input_tensor,
                      bottleneck_tensor):
    tf.logging.info("Creating Bottleneck at {}".format(bottleneck_path))
    image_path = utils.get_image_path(image_lists, label_name, index,
                                      image_dir, category)
    if not gfile.Exists(image_path):
        tf.logging.fatal("File does not exist {}".format(image_path))
    image_data = gfile.FastGFile(image_path, "rb").read()
    try:
        bottleneck_values = run_bottleneck_on_image(sess, image_data,
                                                    jpeg_data_tensor,
                                                    decoded_image_tensor,
                                                    resized_input_tensor,
                                                    bottleneck_tensor)
    except Exception as e:
        raise RuntimeError("Error bottlenecking {}\n{}".format(
            image_path, str(e)))

    bottleneck_string = ",".join(str(x) for x in bottleneck_values)

    bottleneck_directory = "/".join(bottleneck_path.split("/")[:-1])

    utils.create_directory(bottleneck_directory)

    with open(bottleneck_path, "w") as bottleneck_file:
        bottleneck_file.write(bottleneck_string)
예제 #2
0
def store_bottlenecks(sess, image_lists, image_dir, bottleneck_dir,
                      jpeg_data_tensor, decoded_image_tensor,
                      resized_input_tensor, bottleneck_tensor):
    num_bottlenecks = 0
    utils.create_directory(bottleneck_dir)

    for label_name, label_lists in image_lists.items():
        for category in ["training", "testing", "validation"]:
            category_list = label_lists[category]
            for index in range(len(category_list)):
                get_bottleneck(sess, image_lists, label_name, index, image_dir,
                               category, bottleneck_dir, jpeg_data_tensor,
                               decoded_image_tensor, resized_input_tensor,
                               bottleneck_tensor)

                num_bottlenecks += 1
                if num_bottlenecks % 100 == 0:
                    tf.logging.info(
                        "{} bottleneck files created.".format(num_bottlenecks))