def get_playground_images_by_category(source, category=None, offset=0, limit=100): image_api = Images() res = GetImagesByCategoryResponse() try: res_data = GetImagesByCategoryResponseData() count = image_api.get_images_count_by_category_name( category_name=category) images = image_api.get_images_by_category_name( category_name=category, offset=offset, limit=limit) res_data.total_count = count imgs = [] for i in images: i['id'] = i.get('_id') imgs.append(ImageDataset().from_dict(i)) res_data.images = imgs res.message = "Successful" res.data = res_data response_status = 200 except Exception as e: log.error(str(e)) res.message = str(e) response_status = 400 return res, response_status
def main(_): dataset_api = Images() train_writer = tf.python_io.TFRecordWriter(FLAGS.train_output_path) eval_writer = tf.python_io.TFRecordWriter(FLAGS.eval_output_path) train_images = [] eval_images = [] for i in range(1, 4): category_class = str(i) (category_train_images, category_eval_images) = read_from_db(dataset_api, category_class) train_images.extend(category_train_images) eval_images.extend(category_eval_images) print("category_class: {} read from db done!".format(category_class)) random.shuffle(train_images) random.shuffle(eval_images) for image in train_images: tf_data = dict_to_tf_example(image) train_writer.write(tf_data.SerializeToString()) for image in eval_images: tf_data = dict_to_tf_example(image) eval_writer.write(tf_data.SerializeToString()) print("make train/eval TFRecord done!") train_writer.close() eval_writer.close()
def get_images_dataset_categories_counts_by_category(source, category=None): image_api = Images() res = GetImagesCategoriesCountsByCategoryResponse() try: res_data = GetImagesCategoriesCountsByCategoryResponseData() total_count = image_api.get_images_count_by_category_name(category_name=category) valid_count = image_api.get_images_count_by_category_name(category_name=category, valid=True) invalid_count = image_api.get_images_count_by_category_name(category_name=category, valid=False) res_data.total_count = total_count res_data.valid_count = valid_count res_data.invalid_count = invalid_count res.message = "Successful" res.data = res_data response_status = 200 except Exception as e: log.error(str(e)) res.message = str(e) response_status = 400 return res, response_status
def main(_): dataset_api = Images() writer = tf.python_io.TFRecordWriter(FLAGS.output_path) offset = 0 limit = 50 while True: try: res = dataset_api.get_images_by_source("deepfashion", offset=offset, limit=limit) for image in res: print(image) exit(1) tf_data = dict_to_tf_example(image) writer.write(tf_data.SerializeToString()) if limit > len(res): print("done") break else: offset = offset + len(res) except Exception as e: print(str(e)) writer.close()
def main(_): dataset_api = Images() train_writer = tf.python_io.TFRecordWriter(FLAGS.train_output_path) eval_writer = tf.python_io.TFRecordWriter(FLAGS.eval_output_path) train_images = [] eval_images = [] category_class = str(FLAGS.category_class) (train_images, eval_images) = read_from_db(dataset_api, category_class) print("category_class: {} read from db done!".format(category_class)) random.shuffle(train_images) random.shuffle(eval_images) print("----images_num-------") print(len(train_images)) print(len(eval_images)) print("---------------------") for image in train_images: if 'is_valid' in image: if image['is_valid']: tf_data = dict_to_tf_example(image) train_writer.write(tf_data.SerializeToString()) for image in eval_images: if 'is_valid' in image: if image['is_valid']: tf_data = dict_to_tf_example(image) eval_writer.write(tf_data.SerializeToString()) print("make train/eval TFRecord done!") train_writer.close() eval_writer.close()
def update_images_dataset_by_ids(source, ids, valid=True): image_api = Images() res = UpdateImageDatasetResponse() try: image_api.validate_images(ids, valid) res.message = "Successful" response_status = 200 except Exception as e: log.error(str(e)) res.message = str(e) response_status = 400 return res, response_status
print("id = " + str(id)) print("img_file = " + file) key = os.path.join('deepfashion', 'img', 'with_box', id + '.jpg') is_public = True file_url = storage.upload_file_to_bucket(AWS_BUCKET, file, key, is_public=is_public) return file_url def load_image_into_numpy_array(image): (im_width, im_height) = image.size return np.array(image.getdata()).reshape( (im_height, im_width, 3)).astype(np.uint8) if __name__ == '__main__': print('start') image_api = Images() offset = 0 limit = 100 while True: images = None try: images = image_api.get_images_by_source("deepfashion", offset, limit) except Exception as e: print(str(e)) if len(images) == 0: break else: offset = offset + limit
from __future__ import print_function from stylelens_dataset.images import Images from pprint import pprint # create an instance of the API class api_instance = Images() try: ids = [] ids.append('5a718ce0bd44107fbae98994') res = api_instance.validate_images(ids, valid=True) pprint(res) except Exception as e: print("Exception when calling validate_images: %s\n" % e)
file_url = storage.upload_file_to_bucket(AWS_BUCKET, file, key, is_public=is_public) return file_url def get_image_size(img_file): with Image.open(img_file) as img: return img.size if __name__ == '__main__': print('start') dataset_api = Images() bboxes = get_bbox() category_clothes = get_category_clothes() category_images = get_category_images(category_clothes) attribute_clothes = get_attribute_clothes() attribute_images = get_attribute_images(attribute_clothes) i = 0 for img in attribute_images: image = {} image['file'] = img['file'] image['source'] = 'deepfashion' width, height = get_image_size(img['file']) image['width'] = width