From 5911bdec50d5ae652efc2e1f9d215fc0409a6d55 Mon Sep 17 00:00:00 2001 From: Koichi Yoshigoe Date: Fri, 13 Mar 2020 20:45:38 +0900 Subject: [PATCH] Update flake8 and fixed lint --- blueoil/cmd/output_event.py | 31 ++++++++++++++++-------------- blueoil/datasets/base.py | 4 ++-- blueoil/datasets/mscoco.py | 8 ++++---- blueoil/datasets/open_images_v4.py | 2 +- blueoil/datasets/pascalvoc_base.py | 4 ++-- blueoil/networks/base.py | 10 +++++----- setup.cfg | 2 +- 7 files changed, 32 insertions(+), 29 deletions(-) diff --git a/blueoil/cmd/output_event.py b/blueoil/cmd/output_event.py index 1d7109827..1ca6cd697 100644 --- a/blueoil/cmd/output_event.py +++ b/blueoil/cmd/output_event.py @@ -34,7 +34,7 @@ def _value_step_list(event_accumulator, metrics_key): events = event_accumulator.Scalars(metrics_key) return [(event.value, event.step) for event in events] except KeyError as e: - print("Key {} was not found in {}".format(metrics_key, event_accumulator.path)) + print("Key {} was not found in {}\n{}".format(metrics_key, event_accumulator.path, e)) return [] @@ -55,14 +55,16 @@ def output(tensorboard_dir, output_dir, metrics_keys, steps, output_file_base="m event_accumulators.append(event_accumulator) if not metrics_keys: - metrics_keys = {metrics_key - for event_accumulator in event_accumulators - for metrics_key in _get_metrics_keys(event_accumulator)} + metrics_keys = { + metrics_key + for event_accumulator in event_accumulators + for metrics_key in _get_metrics_keys(event_accumulator) + } columns = [_column_name(event_accumulator, metrics_key) for event_accumulator, metrics_key in itertools.product(event_accumulators, metrics_keys)] columns.sort() - df = pd.DataFrame([], columns=columns) + df = pd.DataFrame([], columns=columns) for event_accumulator in event_accumulators: for metrics_key in metrics_keys: @@ -102,13 +104,8 @@ def output(tensorboard_dir, output_dir, metrics_keys, steps, output_file_base="m print(message) -@click.command(context_settings=dict(help_option_names=['-h', '--help'])) -@click.option( - "-i", - "--experiment_id", - help="id of target experiment", - required=True, -) +@click.command(context_settings=dict(help_option_names=["-h", "--help"])) +@click.option("-i", "--experiment_id", help="id of target experiment", required=True) @click.option( "-k", "--metrics_keys", @@ -135,8 +132,14 @@ def output(tensorboard_dir, output_dir, metrics_keys, steps, output_file_base="m def main(output_file_base, metrics_keys, steps, experiment_id): environment.init(experiment_id) - output(environment.TENSORBOARD_DIR, environment.EXPERIMENT_DIR, metrics_keys, steps, output_file_base="metrics",) + output( + environment.TENSORBOARD_DIR, + environment.EXPERIMENT_DIR, + metrics_keys, + steps, + output_file_base="metrics", + ) -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/blueoil/datasets/base.py b/blueoil/datasets/base.py index 255e133ee..96b65417c 100644 --- a/blueoil/datasets/base.py +++ b/blueoil/datasets/base.py @@ -259,8 +259,8 @@ def _validation_data_dir(self): @property def data_dir(self): - if self.subset is "train": + if self.subset == "train": return self._train_data_dir - if self.subset is "validation": + if self.subset == "validation": return self._validation_data_dir diff --git a/blueoil/datasets/mscoco.py b/blueoil/datasets/mscoco.py index 36a03669e..fd34fe3ef 100644 --- a/blueoil/datasets/mscoco.py +++ b/blueoil/datasets/mscoco.py @@ -79,7 +79,7 @@ def coco(self): def _image_ids(self): """Return all files and gt_boxes list.""" - classes = [class_name for class_name in self.classes if class_name is not "__background__"] + classes = [class_name for class_name in self.classes if class_name != "__background__"] target_class_ids = self.coco.getCatIds(catNms=classes) image_ids = [] for target_class_id in target_class_ids: @@ -96,7 +96,7 @@ def _label_from_image_id(self, image_id): width = coco_image["width"] label = np.zeros((height, width), dtype='uint8') - classes = [class_name for class_name in self.classes if class_name is not "__background__"] + classes = [class_name for class_name in self.classes if class_name != "__background__"] for target_class in classes: target_class_id = self.coco.getCatIds(catNms=[target_class])[0] annotation_ids = self.coco.getAnnIds(imgIds=[image_id], catIds=[target_class_id], iscrowd=None) @@ -197,7 +197,7 @@ def coco(self): @functools.lru_cache(maxsize=None) def _image_ids(self): """Return all files and gt_boxes list.""" - classes = [class_name for class_name in self.classes if class_name is not "__background__"] + classes = [class_name for class_name in self.classes if class_name != "__background__"] target_class_ids = self.coco.getCatIds(catNms=classes) image_ids = [] for target_class_id in target_class_ids: @@ -225,7 +225,7 @@ def coco_category_id_to_lmnet_class_id(self, cat_id): @functools.lru_cache(maxsize=None) def _gt_boxes_from_image_id(self, image_id): """Return gt boxes list ([[x, y, w, h, class_id]]) of a image.""" - classes = [class_name for class_name in self.classes if class_name is not "__background__"] + classes = [class_name for class_name in self.classes if class_name != "__background__"] class_ids = set(self.coco.getCatIds(catNms=classes)) boxes = [] diff --git a/blueoil/datasets/open_images_v4.py b/blueoil/datasets/open_images_v4.py index f2c8350b7..af102e42f 100644 --- a/blueoil/datasets/open_images_v4.py +++ b/blueoil/datasets/open_images_v4.py @@ -56,7 +56,7 @@ def _classes_meta(self): with open(self.class_descriptions_csv, 'r') as f: reader = csv.reader(f) for row in reader: - class_name = re.sub('\W', '', row[1]) + class_name = re.sub(r'\W', '', row[1]) classes_meta[row[0]] = class_name return classes_meta diff --git a/blueoil/datasets/pascalvoc_base.py b/blueoil/datasets/pascalvoc_base.py index 335917735..8e09ba757 100644 --- a/blueoil/datasets/pascalvoc_base.py +++ b/blueoil/datasets/pascalvoc_base.py @@ -171,7 +171,7 @@ def _image_ids(self, data_type=None): return all_image_ids image_ids = [ - image_id for image_id, gt_boxes in zip(all_image_ids, all_gt_boxes_list) if len(gt_boxes) is not 0 + image_id for image_id, gt_boxes in zip(all_image_ids, all_gt_boxes_list) if len(gt_boxes) != 0 ] return image_ids @@ -196,7 +196,7 @@ def _all_image_ids(self, data_type=None, is_debug=False): return df.image_id.tolist() def _files_and_annotations(self): - raise NotImplemented() + raise NotImplementedError() def _init_files_and_annotations(self): """Init files and gt_boxes list, Cache these.""" diff --git a/blueoil/networks/base.py b/blueoil/networks/base.py index c74ac0c2c..e93d4ee8a 100644 --- a/blueoil/networks/base.py +++ b/blueoil/networks/base.py @@ -75,7 +75,7 @@ def base(self, images, is_training, *args, **kwargs): tf.Tensor: Inference result. """ - raise NotImplemented() + raise NotImplementedError() def placeholders(self): """Placeholders. @@ -86,7 +86,7 @@ def placeholders(self): tf.compat.v1.placeholder: Placeholders. """ - raise NotImplemented() + raise NotImplementedError() def metrics(self, output, labels): """Metrics. @@ -96,7 +96,7 @@ def metrics(self, output, labels): labels: labels tensor. """ - raise NotImplemented() + raise NotImplementedError() # TODO(wakisaka): Deal with many networks. def summary(self, output, labels=None): @@ -119,7 +119,7 @@ def inference(self, images, is_training): images: images tensor. shape is (batch_num, height, width, channel) """ - raise NotImplemented() + raise NotImplementedError() def loss(self, output, labels): """Loss. @@ -129,7 +129,7 @@ def loss(self, output, labels): labels: labels tensor. """ - raise NotImplemented() + raise NotImplementedError() def optimizer(self, global_step): assert ("learning_rate" in self.optimizer_kwargs.keys()) or \ diff --git a/setup.cfg b/setup.cfg index e69a5cc74..ea4556fe4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -41,7 +41,7 @@ docs = Sphinx==2.4.4 sphinx-autobuild==0.7.1 test = - flake8==3.5.0 + flake8==3.7.9 pytest==5.3.5 pytest-xdist==1.31.0 parameterized==0.7.1