From 3243da72cd44ce7acbea1fca60c64bb77fa315c8 Mon Sep 17 00:00:00 2001 From: lorenzo Date: Thu, 16 May 2019 10:30:52 +0200 Subject: [PATCH] fix pylint --- src/features/preprocess_ki.py | 12 +++++------- src/features/preprocess_nu.py | 22 +++++++++++++--------- src/main.py | 2 +- src/models/trainer.py | 10 +++++----- src/visuals/results.py | 1 - 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/features/preprocess_ki.py b/src/features/preprocess_ki.py index 17c4b61..0efe1de 100644 --- a/src/features/preprocess_ki.py +++ b/src/features/preprocess_ki.py @@ -79,8 +79,6 @@ class PreprocessKitti: for name in self.names_gt: # Extract ground truth - if name == '004223.txt': - aa = 5 path_gt = os.path.join(self.dir_gt, name) basename, _ = os.path.splitext(name) boxes_gt = [] @@ -117,7 +115,7 @@ class PreprocessKitti: with open(os.path.join(self.dir_ann, basename + '.png.pifpaf.json'), 'r') as f: annotations = json.load(f) boxes, keypoints = self.preprocess_pif(annotations) - (inputs, xy_kps), (uv_kps, uv_boxes, _, _) = self.get_input_data(boxes, keypoints, kk) + (inputs, _), (uv_kps, uv_boxes, _, _) = self.get_input_data(boxes, keypoints, kk) except FileNotFoundError: uv_boxes = [] @@ -138,10 +136,10 @@ class PreprocessKitti: boxes_gt.pop(idx_max) dds.pop(idx_max) - with open(self.path_joints, 'w') as f: - json.dump(self.dic_jo, f) - with open(os.path.join(self.path_names), 'w') as f: - json.dump(self.dic_names, f) + with open(self.path_joints, 'w') as file: + json.dump(self.dic_jo, file) + with open(os.path.join(self.path_names), 'w') as file: + json.dump(self.dic_names, file) for phase in ['train', 'val', 'test']: print("Saved {} annotations for phase {}" .format(self.dic_cnt[phase], phase)) diff --git a/src/features/preprocess_nu.py b/src/features/preprocess_nu.py index 50bb5d1..3b97a9a 100644 --- a/src/features/preprocess_nu.py +++ b/src/features/preprocess_nu.py @@ -1,4 +1,6 @@ -import numpy as np +"""Extract joints annotations and match with nuScenes ground truths +""" + import os import sys import time @@ -7,6 +9,8 @@ import logging from collections import defaultdict import datetime +import numpy as np + class PreprocessNuscenes: """ @@ -48,7 +52,7 @@ class PreprocessNuscenes: # Initialize dicts to save joints for training self.dic_jo = {'train': dict(X=[], Y=[], names=[], kps=[], boxes_3d=[], K=[], clst=defaultdict(lambda: defaultdict(list))), - 'val': dict(X=[], Y=[], names=[], kps=[], boxes_3d=[], K=[], + 'val': dict(X=[], Y=[], names=[], kps=[], boxes_3d=[], K=[], clst=defaultdict(lambda: defaultdict(list))), 'test': dict(X=[], Y=[], names=[], kps=[], boxes_3d=[], K=[], clst=defaultdict(lambda: defaultdict(list))) @@ -73,12 +77,12 @@ class PreprocessNuscenes: elif dataset == 'nuscenes_teaser': self.nusc = NuScenes(version='v1.0-trainval', dataroot=dir_nuscenes, verbose=True) - with open("splits/nuscenes_teaser_scenes.txt", "r") as ff: - teaser_scenes = ff.read().splitlines() + with open("splits/nuscenes_teaser_scenes.txt", "r") as file: + teaser_scenes = file.read().splitlines() self.scenes = self.nusc.scene self.scenes = [scene for scene in self.scenes if scene['token'] in teaser_scenes] - with open("splits/split_nuscenes_teaser.json", "r") as ff: - dic_split = json.load(ff) + with open("splits/split_nuscenes_teaser.json", "r") as file: + dic_split = json.load(file) self.split_train = [scene['name'] for scene in self.scenes if scene['token'] in dic_split['train']] self.split_val = [scene['name'] for scene in self.scenes if scene['token'] in dic_split['val']] @@ -147,11 +151,11 @@ class PreprocessNuscenes: exists = os.path.isfile(path_pif) if exists: - with open(path_pif, 'r') as f: - annotations = json.load(f) + with open(path_pif, 'r') as file: + annotations = json.load(file) boxes, keypoints = self.preprocess_pif(annotations, im_size=None) - (inputs, xy_kps), (uv_kps, uv_boxes, _, _) = self.get_input_data(boxes, keypoints, kk) + (inputs, _), (uv_kps, uv_boxes, _, _) = self.get_input_data(boxes, keypoints, kk) for ii, box in enumerate(uv_boxes): idx_max, iou_max = self.get_idx_max(box, boxes_gt) diff --git a/src/main.py b/src/main.py index 522de17..28127e2 100644 --- a/src/main.py +++ b/src/main.py @@ -70,7 +70,7 @@ def cli(): # Training training_parser.add_argument('--joints', help='Json file with input joints', - default='data/arrays/joints-nuscenes-190507-0852.json') + default='data/arrays/joints-nuscenes_teaser-190513-1846.json') training_parser.add_argument('--save', help='whether to not save model and log file', action='store_false') training_parser.add_argument('-e', '--epochs', type=int, help='number of epochs to train for', default=150) training_parser.add_argument('--bs', type=int, default=256, help='input batch size') diff --git a/src/models/trainer.py b/src/models/trainer.py index a4282fa..786acb9 100644 --- a/src/models/trainer.py +++ b/src/models/trainer.py @@ -1,16 +1,16 @@ -import torch -import torch.nn as nn + import copy -import numpy as np -import matplotlib.pyplot as plt import os import datetime import logging from collections import defaultdict -import json import sys import time +import matplotlib.pyplot as plt + +import torch +import torch.nn as nn from torch.utils.data import DataLoader from torch.optim import lr_scheduler diff --git a/src/visuals/results.py b/src/visuals/results.py index 666bdc2..1ea3f30 100644 --- a/src/visuals/results.py +++ b/src/visuals/results.py @@ -1,6 +1,5 @@ import os -import matplotlib import numpy as np import matplotlib.pyplot as plt from matplotlib.patches import Ellipse