How to use _get_image_info method in lisa

Best Python code snippet using lisa_python

dataset.py

Source:dataset.py Github

copy

Full Screen

...40 current_sample = self._load_scene_graph(idx, current_sample)41 return current_sample42 def _get_image_id(self, idx):43 return self.annotation_db[idx][_CONSTANTS["image_id_key"]]44 def _get_image_info(self, idx):45 # Deep copy so that we can directly update the nested dicts46 return copy.deepcopy(self.scene_graph_db[self._get_image_id(idx)])47 def _preprocess_answer(self, sample_info):48 sample_info["answers"] = [49 self.vg_answer_preprocessor(50 {"text": sample_info["answers"][0]},51 remove=["?", ",", ".", "a", "an", "the"],52 )["text"]53 ]54 return sample_info55 def _check_unk(self, sample_info):56 if not self._no_unk:57 return False58 else:59 index = self.answer_processor.word2idx(sample_info["answers"][0])60 return index == self.answer_processor.answer_vocab.UNK_INDEX61 def _load_scene_graph(self, idx, sample):62 if self.scene_graph_db is None:63 return sample64 image_info = self._get_image_info(idx)65 regions = image_info["regions"]66 objects, object_map = self._load_objects(idx)67 if self._return_objects:68 sample.objects = objects69 relationships, relationship_map = self._load_relationships(idx, object_map)70 if self._return_relationships:71 sample.relationships = relationships72 regions, _ = self._load_regions(idx, object_map, relationship_map)73 if self._return_scene_graph:74 sample.scene_graph = regions75 return sample76 def _load_objects(self, idx):77 image_info = self._get_image_info(idx)78 image_height = image_info["height"]79 image_width = image_info["width"]80 object_map = {}81 objects = []82 for obj in image_info["objects"]:83 obj["synsets"] = self.synset_processor({"tokens": obj["synsets"]})["text"]84 obj["names"] = self.name_processor({"tokens": obj["names"]})["text"]85 obj["height"] = obj["h"] / image_height86 obj.pop("h")87 obj["width"] = obj["w"] / image_width88 obj.pop("w")89 obj["y"] /= image_height90 obj["x"] /= image_width91 obj["attributes"] = self.attribute_processor({"tokens": obj["attributes"]})[92 "text"93 ]94 obj = Sample(obj)95 object_map[obj["object_id"]] = obj96 objects.append(obj)97 objects = SampleList(objects)98 return objects, object_map99 def _load_relationships(self, idx, object_map):100 if self._return_relationships is None and self._return_scene_graph is None:101 return None, None102 image_info = self._get_image_info(idx)103 relationship_map = {}104 relationships = []105 for relationship in image_info["relationships"]:106 relationship["synsets"] = self.synset_processor(107 {"tokens": relationship["synsets"]}108 )["text"]109 relationship["predicate"] = self.predicate_processor(110 {"tokens": relationship["predicate"]}111 )["text"]112 relationship["object"] = object_map[relationship["object_id"]]113 relationship["subject"] = object_map[relationship["subject_id"]]114 relationship = Sample(relationship)115 relationship_map[relationship["relationship_id"]] = relationship116 relationships.append(relationship)117 relationships = SampleList(relationships)118 return relationships, relationship_map119 def _load_regions(self, idx, object_map, relationship_map):120 if self._return_scene_graph is None:121 return None, None122 image_info = self._get_image_info(idx)123 image_height = image_info["height"]124 image_width = image_info["width"]125 region_map = {}126 regions = []127 for region in image_info["regions"]:128 for synset in region["synsets"]:129 synset["entity_name"] = self.name_processor(130 {"tokens": [synset["entity_name"]]}131 )["text"]132 synset["synset_name"] = self.synset_processor(133 {"tokens": [synset["synset_name"]]}134 )["text"]135 region["height"] /= image_height136 region["width"] /= image_width...

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 lisa 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