Skip to content

Commit

Permalink
Modernize Python 2 code to get ready for Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed Oct 19, 2018
1 parent f6b72a2 commit 959dffc
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 79 deletions.
1 change: 1 addition & 0 deletions human-detection/lib/utils/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from __future__ import print_function

import numpy as np
from six.moves import xrange
import PIL.Image as Image
import PIL.ImageColor as ImageColor
import PIL.ImageDraw as ImageDraw
Expand Down
4 changes: 3 additions & 1 deletion predict/json/parametric-pose-nms-COCO.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
@author: benjamin
"""
from __future__ import print_function

import json
import numpy as np
from six.moves import xrange
import h5py
import os
import zipfile
Expand Down Expand Up @@ -202,7 +204,7 @@ def test_parametric_pose_NMS_json(delta1,delta2,mu,gamma,outputpath):
for point_id in xrange(17):
if math.isnan(merge_poses[point_id,0]):
merge_poses[point_id,0] = 0
print point_id
print(point_id)
if math.isnan(merge_poses[point_id,1]):
merge_poses[point_id,1] = 1
NMS_preds.write("\t{}\t{}".format(merge_poses[point_id,0]-0.25,merge_poses[point_id,1]-0.25))
Expand Down
1 change: 1 addition & 0 deletions predict/json/parametric-pose-nms-MPII.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import json
import numpy as np
from six.moves import xrange
import h5py
import os
import argparse
Expand Down
1 change: 1 addition & 0 deletions train/src/misc/analyze_occlusion_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pypose import ref
import h5py
import numpy as np
from six.moves import xrange

a = ref.load('mpii','valid')

Expand Down
6 changes: 4 additions & 2 deletions train/src/misc/convert_annot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import print_function
import h5py
import numpy as np
from six.moves import xrange
import sys
import mpii

Expand All @@ -20,7 +22,7 @@
imgnameRef = mpii.annot['annolist'][0][0][0]['image'][:]

for idx in xrange(mpii.nimages):
print "\r",idx,
print("\r",idx, end=' ')
sys.stdout.flush()

for person in xrange(mpii.numpeople(idx)):
Expand Down Expand Up @@ -58,7 +60,7 @@
else: # Training image (something missing in annot)
annot['istrain'] += [2]

print ""
print("")

with h5py.File('mpii-annot.h5','w') as f:
f.attrs['name'] = 'mpii'
Expand Down
11 changes: 6 additions & 5 deletions train/src/misc/examples.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from __future__ import print_function
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# All of these examples are really, really outdated but offer some insights
# into using the python code, if you want to check it out
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


import numpy as np
import pypose as pose
import pypose.mpii as ds # Use this to swap which dataset you want to use
from six.moves import xrange

# Sample dataset generation
if False:
Expand Down Expand Up @@ -48,10 +49,10 @@
pdf = pose.report.PdfPages(pose.ref.posedir+'/img/reports/fwd_back_sample.pdf')

# Add whatever pages you want
print "Doing overall comparison..."
print("Doing overall comparison...")
pose.report.filtercomparison(ds.name, dists, filts, filtnames=filtnames, title=title, pdf=pdf)
for i,filt in enumerate(filts[:-1]):
print "Generating images for - %s..." % filtnames[i]
print("Generating images for - %s..." % filtnames[i])
pose.report.sampleimages(ds, preds, dists=dists, pdf=pdf, title=filtnames[i], filt=filt)
pose.report.sampleimages(ds, preds, dists=dists, pdf=pdf, title=filtnames[i], filt=filt, get_worst=True)

Expand Down Expand Up @@ -81,11 +82,11 @@
title='Performance Comparison - Torso Deviation from Vertical'
pdf = pose.report.PdfPages(pose.ref.posedir+'/img/reports/torso_angle_sample.pdf')

print "Doing overall comparison..."
print("Doing overall comparison...")
pose.report.filtercomparison(ds.name, dists, filts, filtnames=filtnames, title=title, pdf=pdf)
for i in xrange(7):
# This loop will only generate poor performing images for the first filter (people who are upright)
print "Generating images for page - %d..." % i
print("Generating images for page - %d..." % i)
pose.report.sampleimages(ds, preds, dists=dists, pdf=pdf, title=filtnames[0], filt=filts[0],
get_worst=True, page_num=i+1)

Expand Down
19 changes: 10 additions & 9 deletions train/src/misc/monitor_experiments.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
Expand All @@ -11,17 +12,17 @@
try:
experiments_to_show = sys.argv[1].split(',')
except:
print "Error: No experiments provided"
print("Error: No experiments provided")
exit()

print "Monitoring the following experiments:",
for exp in experiments_to_show: print exp,
print ""
print("Monitoring the following experiments:", end=' ')
for exp in experiments_to_show: print(exp, end=' ')
print("")

track_multiple = sys.argv[2] == '1'
if track_multiple:
exp_to_track = experiments_to_show[0]
print "Tracking all variations of:",exp_to_track
print("Tracking all variations of:",exp_to_track)
experiments_to_show.remove(exp_to_track)

def readlog(filepath):
Expand Down Expand Up @@ -55,9 +56,9 @@ def readlog(filepath):
if not subdirname in experiments_to_show:
experiments_to_show += [subdirname]

print "Updated experiments to show:",
for exp in experiments_to_show: print exp,
print ""
print("Updated experiments to show:", end=' ')
for exp in experiments_to_show: print(exp, end=' ')
print("")

idx = [1, 2, 0] # Epoch, Loss, Accuracy indices

Expand Down Expand Up @@ -111,6 +112,6 @@ def readlog(filepath):
axs[k].set_ylim(0,1)

axs['Test accuracy'].legend(loc='lower right', fontsize=10)
print time.strftime('%X %x %Z')
print(time.strftime('%X %x %Z'))
plt.show()
plt.pause(900)
4 changes: 3 additions & 1 deletion train/src/misc/mpii.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import scipy.io
import scipy.misc
from six import text_type
from six.moves import xrange
import numpy as np

# Load in annotations
Expand Down Expand Up @@ -68,7 +70,7 @@ def partinfo(idx, person, part):
if 'is_visible' in parts_info.dtype.fields:
v = parts_info[i]['is_visible']
v = v[0][0] if len(v) > 0 else 1
if type(v) is unicode:
if type(v) is text_type:
v = int(v)
else:
v = 1
Expand Down
3 changes: 2 additions & 1 deletion train/src/misc/pck_figs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import matplotlib.pyplot as plt
from scipy.io import loadmat
import numpy as np
from six.moves import xrange
import h5py

def setuppdjplot(ax, i):
Expand Down Expand Up @@ -180,4 +181,4 @@ def pdjdata(dataset, dists, partidx, rng=None, filt=None):
ax.set_xlim(0,100)
ax.set_ylim(0,1)

plt.show()
plt.show()
Loading

0 comments on commit 959dffc

Please sign in to comment.