def get_classes(self): try: label_map_string = '' print("getting " + self.label_file + ' from ' + self.bucket) if self.use_gcs: blob = self.gcs_bucket.get_blob(self.label_file) label_map_string = blob.download_as_string().decode('utf-8') else: obj = self.s3.get_object(Bucket=self.bucket, Key=self.label_file) label_map_string = obj['Body'].read().decode('utf-8') print("got " + self.label_file) self.label_map = {} self.label_map = labelmap.StringIntLabelMap() self.labelmap_dict = {} text_format.Merge(label_map_string, self.label_map) self.categories = [] for item in self.label_map.item: self.labelmap_dict[item.name] = item.id self.categories.append({'id': item.id, 'name': item.name}) except botocore.exceptions.ClientError as e: if e.response['Error']['Code'] == "404": self.labelmap_dict = {} print(self.label_file + ' was not found') else: print(e) raise ValueError('Error getting ' + self.label_file + ' in ' + self.bucket)
def load_labelmap(path): """Loads label map proto. Args: path: path to StringIntLabelMap proto text file. Returns: a StringIntLabelMapProto """ with tf.gfile.GFile(path, 'r') as fid: label_map_string = fid.read() label_map = string_int_label_map_pb2.StringIntLabelMap() try: text_format.Merge(label_map_string, label_map) except text_format.ParseError: label_map.ParseFromString(label_map_string) return label_map