How to use set_json method in localstack

Best Python code snippet using localstack_python

mix_sets.py

Source:mix_sets.py Github

copy

Full Screen

1import json2import os3import sys4from collections import defaultdict5usage_text = """6This script creates a coco annotation file by mixing one or more existing annotation files.7Usage: python data/scripts/mix_sets.py output_name [set1 range1 [set2 range2 [...]]]8To use, specify the output annotation name and any number of set + range pairs, where the sets9are in the form instances_<set_name>.json and ranges are python-evalable ranges. The resulting10json will be spit out as instances_<output_name>.json in the same folder as the input sets.11For instance,12 python data/scripts/mix_sets.py trainval35k train2014 : val2014 :-500013This will create an instance_trainval35k.json file with all images and corresponding annotations14from train2014 and the first 35000 images from val2014.15You can also specify only one set:16 python data/scripts/mix_sets.py minival5k val2014 -5000:17This will take the last 5k images from val2014 and put it in instances_minival5k.json.18"""19annotations_path = 'data/coco/annotations/instances_%s.json'20fields_to_combine = ('images', 'annotations')21fields_to_steal = ('info', 'categories', 'licenses')22if __name__ == '__main__':23 if len(sys.argv) < 4 or len(sys.argv) % 2 != 0:24 print(usage_text)25 exit()26 out_name = sys.argv[1]27 sets = sys.argv[2:]28 sets = [(sets[2*i], sets[2*i+1]) for i in range(len(sets)//2)]29 out = {x: [] for x in fields_to_combine}30 for idx, (set_name, range_str) in enumerate(sets):31 print('Loading set %s...' % set_name)32 with open(annotations_path % set_name, 'r') as f:33 set_json = json.load(f)34 # "Steal" some fields that don't need to be combined from the first set35 if idx == 0:36 for field in fields_to_steal:37 out[field] = set_json[field]38 39 print('Building image index...')40 image_idx = {x['id']: x for x in set_json['images']}41 print('Collecting annotations...')42 anns_idx = defaultdict(lambda: [])43 for ann in set_json['annotations']:44 anns_idx[ann['image_id']].append(ann)45 export_ids = list(image_idx.keys())46 export_ids.sort()47 export_ids = eval('export_ids[%s]' % range_str, {}, {'export_ids': export_ids})48 print('Adding %d images...' % len(export_ids))49 for _id in export_ids:50 out['images'].append(image_idx[_id])51 out['annotations'] += anns_idx[_id]52 print('Done.\n')53 print('Saving result...')54 with open(annotations_path % (out_name), 'w') as out_file:...

Full Screen

Full Screen

set_wrapper.py

Source:set_wrapper.py Github

copy

Full Screen

1from utils import nft_utils2from utils.nft_errors import NFTError, Error3from parsers import set_parser4def list_all_sets():5 return set_parser.parse_sets(nft_utils.nft_list_ruleset(nna=True))6def get_set(set_id):7 sets = list_all_sets()8 return set_parser.parse_set(set_id, sets)9def create_set(set_json):10 set_json['family'], set_json['table'] = set_json['table'].split(':')11 cmd_string = 'add set {family} {table} {name} {{ type {dataType}; }}'.format(**set_json)12 cmd = nft_utils.nft_command(cmd_string)13 cmd_result = cmd.wait()14 if cmd_result == 0:15 nft_utils.close_nft_command(cmd)16 set = set_json17 set['id'] = '{family}:{table}:{name}'.format(**set_json)18 set['items'] = set['items'] if set['items'] else None19 set['table'] = set['family'] + ':' + set['table']20 return set21 else:22 raise NFTError(Error(cmd.stdout.readlines()))23def update_set(set_json):24 set_json['family'], set_json['table'] = set_json['table'].split(':')25 if set_json['items']:26 cmd_string = 'add element {family} {table} {name} {{ {items} }}'.format(**set_json)27 cmd = nft_utils.nft_command(cmd_string)28 cmd_result = cmd.wait()29 else:30 cmd_result = 031 if cmd_result == 0:32 nft_utils.close_nft_command(cmd)33 set = set_json34 set['table'] = set['family'] + ':' + set['table']35 return set36 else:...

Full Screen

Full Screen

json_metadata_intersect.py

Source:json_metadata_intersect.py Github

copy

Full Screen

1import csv2import os3json_folder_path = r'D:\miniGlump\RecommenderSystems\assets\extracted_content_ml-latest'4movies_csv_paths = [5 r'D:\miniGlump\RecommenderSystems\assets\ml-20m',6 r'D:\miniGlump\RecommenderSystems\assets\ml-25m',7]8set_json = set()9for name in os.listdir(json_folder_path):10 set_json.add(int(name.rstrip('.json')))11print('json: ', len(set_json))12for path in movies_csv_paths:13 set_csv = set()14 with open(path + r'\movies.csv', encoding='utf8') as f:15 reader = csv.reader(f)16 next(reader)17 for row in reader:18 set_csv.add(int(row[0]))19 print(path)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful