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 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() 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 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
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 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()
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)
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: offset = 0 limit = 100 while True: res = api_instance.get_images_by_category_class("1", offset=offset, limit=limit) pprint(res) if limit > len(res): break else: offset = offset + limit except Exception as e: print("Exception when calling get_images_by_source: %s\n" % e)
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() image = {} image['file'] = "xxxkkkx" image['source'] = 'deepfashion' size = {} size['width'] = 300 size['height'] = 500 size['depth'] = 3 objects = [] object = {} box = {} box['x1'] = 10.0 box['y1'] = 10.0 box['x2'] = 40.0 box['y2'] = 60.0 object['name'] = 'xxx' object['box'] = box objects.append(object) image['size'] = size image['objects'] = objects try: api_response = api_instance.add_image(image)
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: offset = 0 limit = 10 res = api_instance.get_images_by_category_name("Blouse", offset=offset, limit=limit) pprint(res) except Exception as e: print("Exception when calling get_images_by_category_name: %s\n" % e)
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: api_response = api_instance.get_images_by_source("deepfashion") pprint(api_response) except Exception as e: print("Exception when calling get_images_by_source: %s\n" % e)
im = Image.open(f) area = (left, top, left + abs(left - right), top + abs(bottom - top)) cropped = im.crop(area) cropped.save(new_file_name) uploaded_path = upload_image_to_storage(new_file_name) os.remove(new_file_name) except Exception as e: print(e) return uploaded_path if __name__ == '__main__': print('start') image_api = Images() object_api = Objects() offset = 0 limit = 100 while True: try: res = image_api.get_images_by_source(source='deepfashion', offset=offset, limit=limit) for image in res: cropped_file = crop(image) image['url'] = cropped_file image['image_id'] = str(image['_id'])
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
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: res = api_instance.get_images_count_by_category_name("Blouse") pprint(res) except Exception as e: print("Exception when calling get_images_by_category_name: %s\n" % e)