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

Standardize Imports I, #176 #206

Merged
merged 6 commits into from
Sep 29, 2017
Merged

Standardize Imports I, #176 #206

merged 6 commits into from
Sep 29, 2017

Conversation

zuphilip
Copy link
Collaborator

@zuphilip zuphilip commented Apr 28, 2017

The import statements for the main commands ocropus-* are
standardized:

  • Put different import statements into different lines
  • Group them into (1) standard imports, (2) third party
    imports, (3) local modules
  • Avoid the "from pylab import *"
  • Use rather "import numpy as np", "import matplotlib.pyplot as plt"

Moreover, some unused import statements were deleted and a very
few nits for readibility are done.

This work is heavily based on the work by @QuLogic in the branch
https://github.com/QuLogic/ocropy/commits/standard-import
See also #176 .

All commands from the current pipeline are tested to still work
in the usual calls (especially run-test and run-rtrain). Even more, the
outputs before and afterwards is exactly the same.

Some imports are not anymore used because the models or other
data files are not anymore downloaded with this script. Some
uncommented parts are now deleted.
The import statements for the main commands ocropus-* are
standardized:
 * Put different import statements into different lines
 * Group them into (1) standard imports, (2) third party
   imports, (3) local modules
 * Avoid the "from pylab import *"
 * Use rather "import numpy as np", "import matplotlib.pyplot as plt"

Moreover, some unused import statements were deleted and a very
few nits for readibility are done.

This work is heavily based on the work by @QuLogic in the branch
https://github.com/QuLogic/ocropy/commits/standard-import

All commands from the current pipeline are tested to still work
in the usual calls (especially run-test and run-rtrain).
@zuphilip
Copy link
Collaborator Author

I tried to automatically check the addition of a namespace to the relevant functions (i.e. these are the ones I found so far in the ocropus code) with these lines:

# used functions from numpy need now a prefix 'np.'
perl -ne 'print "$. $_" if /([^.]|^)(amax|amin|arange|array|asarray|clip|dtype\(|isnan|linspace|maximum\(|mean|median\(|minimum\(|ones|random|rand|randn|randint|transpose|var|vstack|zeros)/' ocropus-*

# used functions from matplotlib.pyplot need now a prefix 'plt.'
perl -ne 'print "$. $_" if /([^.]|^)(clf|cm.gray|cm.hot|draw|figure|gca|ginput|gray\(|imshow|\bion\(|\bplot|rc\(|rcParams|savefig|subplot|title)/' ocropus-*

@ChillarAnand
Copy link
Contributor

Looks good. Any updates on this? We can also use importmagic to automatically fix imports.

ocropus-dewarp Outdated
lnorm.measure(amax(line)-line)
line = lnorm.normalize(line,cval=amax(line))
lnorm.measure(np.amax(line)-line)
line = lnorm.normalize(line,cval=np.amax(line))
scipy.misc.imsave(base+".dew.png",line)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We still need scipy here, cf. Travis output.

ocropus-linegen Outdated
c = array([w/2.0,h/2])
d = c-dot(m,c)+array([randn()*delta,randn()*delta])
c = np.array([w/2.0,h/2])
d = c-dot(m,c)+np.array([np.random.randn()*delta,np.random.randn()*delta])
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

NameError: global name 'dot' is not defined -> Thus, I guess this should be np.dot(...)

@zuphilip
Copy link
Collaborator Author

@ChillarAnand Any checking with importmagic would be appreciated. Moreover, I would like to wait for #234.

@ChillarAnand
Copy link
Contributor

importmagic doesnt work out of the box. I have written a wrapper script and it works only on Python 3.

Any timeline for this PR?

@zuphilip
Copy link
Collaborator Author

Okay, I understand. Actually, we still concentrate on Python 2 and the PR you mentioned is for a separate Python 3 branch. In general it might be hard work to have the whole OCRopus work for Python 2 and Python 3.

@kba kba merged commit d823ba4 into ocropus-archive:master Sep 29, 2017
@zuphilip
Copy link
Collaborator Author

Wow, that was fast :-) I hope that no error was created in the last round of solving merge conflict, because I didn't test it myself much, but simply relied on Travis and the extended tests we have now...

@zuphilip zuphilip deleted the imports branch September 29, 2017 14:23
@kba
Copy link
Collaborator

kba commented Sep 29, 2017

:shipit: :shipit: :shipit:

But seriously, if we'll see regressions from this, it will be fairly obvious, missing imports or undeclared vars.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants