def __next__(self): if (not self.take_max == -1) and (self.took >= self.take_max): raise StopIteration name = None if self.numbers_from_index == None: name = str(self.took) else: if self.took >= len(self.numbers_from_index): raise StopIteration name = str(self.numbers_from_index[self.took]) next_file_metadata = { 'name': name, 'extension': 'json', 'dir': self.folder_path } next_file_path = getFilePath(next_file_metadata) if not os.path.exists(next_file_path): raise StopIteration content = None with open(next_file_path) as next_file: try: content = json.load(next_file) except json.decoder.JSONDecodeError: self.errors_report.write(next_file_path, '') self.took += 1 return self.__next__() self.took += 1 if self.return_names: return (content, int(name)) else: return content
def getAnnotationsData(files_metadata): txt_files = filter(lambda f: f['extension'] == 'txt', files_metadata) annotations_data = {} for file_data in txt_files: file_path = getFilePath(file_data) file_content = None with open(file_path) as file: file_content = file.read() if file_content.find('\t') == -1: continue file_content_lines = filter(lambda l: l != '', file_content.split('\n')) for line in file_content_lines: splited = re.split('\t| ', line) if len(splited) < 12: continue image_file_name = splited[2] emotion = splited[11] if emotion == 'FEMALE' or emotion == 'MALE' or emotion == '': continue dir_name_1 = os.path.basename(os.path.dirname(file_data['dir'])) dir_name_2 = os.path.basename(file_data['dir']) key = '_'.join([dir_name_1, dir_name_2, image_file_name]) annotations_data[key] = emotion return annotations_data
def __iter__(self): path_to_file = getFilePath(self.file) video = getVideo(path_to_file) self.frame_count = video['frameCount'] video['video'].release() self.current_frame_no = 0 return self
def getAnnotationsData(files_metadata): json_files = filter(lambda f: f['extension'] == 'json', files_metadata) annotations_data = {} for file in json_files: file_path = getFilePath(file) json_from_file = load_json_from_file(file_path) key = file['name'] annotations_data[key] = json_from_file return annotations_data
def getAnnotationsDataForExtensions(files_metadata, extensions): joined = {} for file_metadata in filter(lambda file_metadata: file_metadata['extension'] in extensions, files_metadata): file_path = getFilePath(file_metadata) with open(file_path) as file: key = file_path content = file.read().split('\n') joined[key]=content return joined
def getAnnotationsData(files_metadata): joined = {} for file_metadata in filter( lambda file_metadata: file_metadata['extension'] == 'json', files_metadata): file_path = getFilePath(file_metadata) with open(file_path) as file: key = file_metadata['name'].split('.')[0] joined[key] = json.load(file) return joined
def getAnnotationsData(files_metadata): csv_files = filter(lambda f: f['extension'] == 'csv', files_metadata) annotations_data = {} for file_data in csv_files: file_path = getFilePath(file_data) with open(file_path) as file: reader = csv.reader(file) i = 0 for row in reader: if row[0] == 'subDirectory_filePath': continue image_file_subpath = row[0] image_annotation = dict(zip(attributes_names, row[1:])) if image_file_subpath in annotations_data: print('f**k', image_file_subpath, file_path) exit() annotations_data[image_file_subpath] = image_annotation return annotations_data
def getAnnotationsData(files_metadata): result = {} for file_metadata in files_metadata: if file_metadata['extension'] == 'txt': attributes_group_name = '_'.join(file_metadata['name'].split('_')[1:-1]) with open(getFilePath(file_metadata)) as f: f.readline() attributes_names = f.readline()[:-1].split(' ') if attributes_group_name == 'bbox': attributes_names = attributes_names[1:] for line in f: line_without_multiple_spaces = ' '.join(line.split()) line_splited = line_without_multiple_spaces[:-1].split(' ') image_file_name = line_splited[0] attributes_values = line_splited[1:] if not (image_file_name in result): result[image_file_name] = {} result[image_file_name][attributes_group_name] = dict(zip(attributes_names, attributes_values)) return result
def loadJson(file): file_path = getFilePath(file) content = None with open(file_path) as file: content = json.load(file) return content