Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery refactored master branch #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 1 addition & 3 deletions gui_cvs/hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ def __init__(self, *args):
super(MyApp, self).__init__(*args)

def main(self):
lbl = gui.Label("Hello world!", width=100, height=30)

# return of the root widget
return lbl
return gui.Label("Hello world!", width=100, height=30)
Comment on lines -7 to +8
Copy link
Author

Choose a reason for hiding this comment

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

Function MyApp.main refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)


initcv(cvs.openwin)
startcv(MyApp)
4 changes: 2 additions & 2 deletions gui_cvs/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def on_column_count_change(self, emitter, value, table):
table.set_column_count(int(value))

def fill_table(self, emitter, table):
for ri in range(0, table.row_count()):
for ci in range(0, table.column_count()):
for ri in range(table.row_count()):
for ci in range(table.column_count()):
Comment on lines -57 to +58
Copy link
Author

Choose a reason for hiding this comment

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

Function MyApp.fill_table refactored with the following changes:

  • Replace range(0, x) with range(x) (remove-zero-from-range)

table.item_at(ri, ci).set_text("row:%s,column:%s"%(str(ri),str(ci)))

def on_use_title_change(self, emitter, value, table):
Expand Down
3 changes: 1 addition & 2 deletions gui_wizard/helloworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class untitled(App):
def __init__(self, *args, **kwargs):
#DON'T MAKE CHANGES HERE, THIS METHOD GETS OVERWRITTEN WHEN SAVING IN THE EDITOR
if not 'editing_mode' in kwargs.keys():
if 'editing_mode' not in kwargs.keys():
Copy link
Author

Choose a reason for hiding this comment

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

Function untitled.__init__ refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

super(untitled, self).__init__(*args, static_file_path={'my_res':'./res/'})

def idle(self):
Expand Down Expand Up @@ -43,7 +43,6 @@ def construct_ui(self):

def onclick_button(self, emitter):
self.mainContainer.children['label'].set_text('hello world')
pass
Copy link
Author

Choose a reason for hiding this comment

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

Function untitled.onclick_button refactored with the following changes:

  • Remove redundant pass statement (remove-redundant-pass)




Expand Down
2 changes: 1 addition & 1 deletion src/cvs/webcam.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class untitled(App):
def __init__(self, *args, **kwargs):
#DON'T MAKE CHANGES HERE, THIS METHOD GETS OVERWRITTEN WHEN SAVING IN THE EDITOR
if not 'editing_mode' in kwargs.keys():
if 'editing_mode' not in kwargs.keys():
Copy link
Author

Choose a reason for hiding this comment

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

Function untitled.__init__ refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

super(untitled, self).__init__(*args, static_file_path={'my_res':'./res/'})

def idle(self):
Expand Down
17 changes: 8 additions & 9 deletions src/facencnn/facepose.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ def main():

fcount=0
start = time.time()

while True:
sleep(30)
img =cvs.read()

if img is None :
continue
fcount=fcount+1

fcount += 1
# global lbs
lbs = 'Average FPS: '+ str(fcount / (time.time() - start))
cvs.setLbs(lbs)

if camid==1:
img=cv2.flip(img,1)

#img=cv2.resize(img,(112,112))
image_char = img.astype(np.uint8).tostring()
rets = facerecog.getfacepose(img.shape[0], img.shape[1], image_char)

#print 'rets:',rets
for ret in rets:
for ret in rets:
Comment on lines -13 to +34
Copy link
Author

Choose a reason for hiding this comment

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

Function main refactored with the following changes:

  • Replace assignment with augmented assignment (aug-assign)
  • Replace range(0, x) with range(x) (remove-zero-from-range)

#for ret in each:
print ('draw bounding box for the face')
#cvs.infoshow('draw bounding box for the face')
Expand All @@ -45,10 +45,10 @@ def main():
#print keypoint
p1 = (int(rect[0]), int(rect[1]))
p2 = (int(rect[0]+rect[2]), int(rect[1]+rect[3]))

#draw_name(img, rect, ret['name'])
cvs.rectangle(img, p1,p2, (0, 255, 0) , 3, 1)
for p in range(0,106):
for p in range(106):
#print p*2,' = ',keypoint[p*2]
#print p*2+1,' = ',keypoint[p*2+1]
k1=int(rect[0]+keypoint[p*2])
Expand All @@ -65,7 +65,6 @@ def __init__(self, *args):
def idle(self):
#idle function called every update cycle
self.lbl.set_text(cvs.getLbs())
pass
Copy link
Author

Choose a reason for hiding this comment

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

Function MyApp.idle refactored with the following changes:

  • Remove redundant pass statement (remove-redundant-pass)


def main(self):
#creating a container VBox type, vertical (you can use also HBox or Widget)
Expand Down
4 changes: 1 addition & 3 deletions src/handtf/utils/detector_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ def draw_box_on_image(num_hands_detect, score_thresh, scores, boxes, classes, im
id ='closed'
avg_width = 3.0 # To compensate bbox size change

if i == 0: color = color0
else: color = color1

color = color0 if i == 0 else color1
Copy link
Author

Choose a reason for hiding this comment

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

Function draw_box_on_image refactored with the following changes:

  • Replace if statement with if expression (assign-if-exp)

(left, right, top, bottom) = (boxes[i][1] * im_width, boxes[i][3] * im_width,
boxes[i][0] * im_height, boxes[i][2] * im_height)
p1 = (int(left), int(top))
Expand Down
15 changes: 7 additions & 8 deletions src/handtf/webcam.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def main():
continue
frame = cv2.resize(frame, (640, 480))

if im_height == None:
if im_height is None:
Copy link
Author

Choose a reason for hiding this comment

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

Function main refactored with the following changes:

  • Use x is None rather than x == None (none-compare)

im_height, im_width = frame.shape[:2]

# Convert image to rgb since opencv loads images in bgr, if not accuracy will decrease
Expand All @@ -50,8 +50,8 @@ def main():
# Run image through tensorflow graph
boxes, scores, classes = detector_utils.detect_objects(
frame, detection_graph, sess)


# Draw bounding boxeses and text
detector_utils.draw_box_on_image(
num_hands_detect, score_thresh, scores, boxes, classes, im_width, im_height, frame)
Expand All @@ -61,21 +61,21 @@ def main():
elapsed_time = (datetime.datetime.now() -
start_time).total_seconds()
fps = num_frames / elapsed_time

# Display FPS on frame
lbs = "FPS : " + str("{0:.2f}".format(fps))
cvs.setLbs(lbs)

if args['display']:

detector_utils.draw_text_on_image("FPS : " + str("{0:.2f}".format(fps)), frame)

cvs.imshow(cv2.cvtColor(frame, cv2.COLOR_RGB2BGR))


print("Average FPS: ", str("{0:.2f}".format(fps)))



except KeyboardInterrupt:
print("Average FPS: ", str("{0:.2f}".format(fps)))
Expand All @@ -88,7 +88,6 @@ def __init__(self, *args):
def idle(self):
#idle function called every update cycle
self.lbl.set_text(cvs.getLbs())
pass
Copy link
Author

Choose a reason for hiding this comment

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

Function MyApp.idle refactored with the following changes:

  • Remove redundant pass statement (remove-redundant-pass)


def main(self):
# initcv(process)
Expand Down
3 changes: 1 addition & 2 deletions src/mutilpose/posenet/converter/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

def load_config(config_name='config.yaml'):
cfg_f = open(os.path.join(BASE_DIR, config_name), "r+")
cfg = yaml.load(cfg_f)
return cfg
return yaml.load(cfg_f)
Copy link
Author

Choose a reason for hiding this comment

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

Function load_config refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)

8 changes: 4 additions & 4 deletions src/mutilpose/posenet/decode_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@


def within_nms_radius(poses, squared_nms_radius, point, keypoint_id):
for _, _, pose_coord in poses:
if np.sum((pose_coord[keypoint_id] - point) ** 2) <= squared_nms_radius:
return True
return False
return any(
np.sum((pose_coord[keypoint_id] - point) ** 2) <= squared_nms_radius
for _, _, pose_coord in poses
)
Comment on lines -8 to +11
Copy link
Author

Choose a reason for hiding this comment

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

Function within_nms_radius refactored with the following changes:

  • Use any() instead of for loop (use-any)



def within_nms_radius_fast(pose_coords, squared_nms_radius, point):
Expand Down
3 changes: 1 addition & 2 deletions src/mutilpose/posenet/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ def load_config(model_ord):
output_stride = converter_cfg['outputStride']
checkpoint_name = checkpoints[model_ord]

model_cfg = {
return {
'output_stride': output_stride,
'checkpoint_name': checkpoint_name,
}
return model_cfg
Comment on lines -28 to -32
Copy link
Author

Choose a reason for hiding this comment

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

Function load_config refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)



def load_model(model_id, sess, model_dir=MODEL_DIR):
Expand Down
3 changes: 1 addition & 2 deletions src/mutilpose/posenet/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ def draw_keypoints(
if ks < min_part_confidence:
continue
cv_keypoints.append(cv2.KeyPoint(kc[1], kc[0], 10. * ks))
out_img = cv2.drawKeypoints(img, cv_keypoints, outImage=np.array([]))
return out_img
return cv2.drawKeypoints(img, cv_keypoints, outImage=np.array([]))
Copy link
Author

Choose a reason for hiding this comment

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

Function draw_keypoints refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)



def get_adjacent_keypoints(keypoint_scores, keypoint_coords, min_confidence=0.1):
Expand Down
1 change: 0 additions & 1 deletion src/mutilpose/webcam_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ def __init__(self, *args):
def idle(self):
#idle function called every update cycle,we show the FPS
self.lbl.set_text(cvs.getLbs())
pass
Copy link
Author

Choose a reason for hiding this comment

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

Function MyApp.idle refactored with the following changes:

  • Remove redundant pass statement (remove-redundant-pass)


def main(self):
#creating a container VBox type, vertical (you can use also HBox or Widget)
Expand Down
27 changes: 13 additions & 14 deletions src/singlepose/webpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def main():
displacementFwd=detection_graph.get_tensor_by_name('displacement_fwd_2:0')
displacementBwd=detection_graph.get_tensor_by_name('displacement_bwd_2:0')


Copy link
Author

Choose a reason for hiding this comment

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

Function main refactored with the following changes:

  • Replace assignment with augmented assignment (aug-assign)
  • Replace range(0, x) with range(x) (remove-zero-from-range)

fcount=-1
start = time.time()
while True:
Expand All @@ -50,8 +50,8 @@ def main():
sleep(50)
continue

fcount=fcount+1

fcount += 1
# global lbs
lbs = 'Average FPS: '+ str(fcount / (time.time() - start))
cvs.setLbs(lbs)
Expand All @@ -60,8 +60,8 @@ def main():
input_image = resizeimg(img,width,height)
tmpimg = img
tmpimg = cv2.resize(tmpimg, (width,height))


input_image = np.array(input_image,dtype=np.float32)
input_image = input_image.reshape(1,width,height,3)
heatmaps_result,offsets_result,displacementFwd_result,displacementBwd_result = sess.run(
Expand All @@ -71,7 +71,7 @@ def main():
[255, 0, 255], [255, 0, 255]]



pairs = [[5,6],[5,7],[6,8],[7,9],[8,10],[5,11],[6,12],[11,12],[11,13],[12,14],[13,15],[14,16]]
keypoint = []
ckeypoint = []
Expand All @@ -81,18 +81,18 @@ def main():
offsets_result=offsets_result[0]
bbb= np.transpose(offsets_result,(2, 0, 1))

for k in range(0,17):
for k in range(17):
heatmaps_result=aaaa[k]
maxheat=np.max(heatmaps_result)
re=np.where(heatmaps_result==maxheat)

ry=re[0][0]
rx=re[1][0]
offsets_resulty=bbb[0+k]
offsets_resultx=bbb[17+k]
ofx=int(offsets_resultx[ry][rx]+0.5)
ofy=int(offsets_resulty[ry][rx]+0.5)

px=(rx)*16+ofx
py=(ry)*16+ofy
if maxheat>0.7 :
Expand All @@ -102,7 +102,7 @@ def main():
else :
keypoint.append(-1);
keypoint.append(-1);

ckeypoint.append(keypoint[0])
ckeypoint.append(keypoint[1])

Expand All @@ -118,11 +118,11 @@ def main():
ckeypoint.append(keypoint[2*i+1])
ckeypoint.append(keypoint[2*i+2])
ckeypoint.append(keypoint[2*i+2+1])

for pair in pairs:
if ckeypoint[2*pair[0]]>0 and ckeypoint[2*pair[1]]>0 :
cvs.line(tmpimg,(ckeypoint[2*pair[0]],ckeypoint[2*pair[0]+1]),(ckeypoint[2*pair[1]],ckeypoint[2*pair[1]+1]),(0,0,255),1)

cvs.imshow(tmpimg)
print ('frames:',fcount)

Expand All @@ -134,8 +134,7 @@ def __init__(self, *args):

def idle(self):
#idle function called every update cycle
self.lbl.set_text(cvs.getLbs())
pass
self.lbl.set_text(cvs.getLbs())
Copy link
Author

Choose a reason for hiding this comment

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

Function MyApp.idle refactored with the following changes:

  • Remove redundant pass statement (remove-redundant-pass)


def main(self):
#creating a container VBox type, vertical (you can use also HBox or Widget)
Expand Down