Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

Update flake8 and fixed lint #923

Merged
merged 2 commits into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions blueoil/cmd/output_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 []


Expand All @@ -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:
Expand Down Expand Up @@ -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",
Expand All @@ -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()
4 changes: 2 additions & 2 deletions blueoil/datasets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions blueoil/datasets/mscoco.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 = []
Expand Down
2 changes: 1 addition & 1 deletion blueoil/datasets/open_images_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions blueoil/datasets/pascalvoc_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is not is not allowed by newer flake8?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, errors F632 use ==/!= to compare str, bytes, and int literals are appeared

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is compares identity (whether two reference points to the same object). == compares values.
there's no point using is when comparing int values.

]

return image_ids
Expand All @@ -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."""
Expand Down
10 changes: 5 additions & 5 deletions blueoil/networks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def base(self, images, is_training, *args, **kwargs):
tf.Tensor: Inference result.

"""
raise NotImplemented()
raise NotImplementedError()

def placeholders(self):
"""Placeholders.
Expand All @@ -86,7 +86,7 @@ def placeholders(self):
tf.compat.v1.placeholder: Placeholders.

"""
raise NotImplemented()
raise NotImplementedError()

def metrics(self, output, labels):
"""Metrics.
Expand All @@ -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):
Expand All @@ -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.
Expand All @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down