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

Remove useless global variable in custom_utils #454

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

belotfa
Copy link

@belotfa belotfa commented Jan 15, 2020

Removing this variable allows to use dfferent instances of the same class (CustomImagePrediction) at the same time without using the same model_json.

Removing this variable allows to use dfferent instances of the same class (CustomImagePrediction) at the same time without using the same model_json.
@codecov
Copy link

codecov bot commented Jan 15, 2020

Codecov Report

Merging #454 into master will increase coverage by 1.11%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master     #454      +/-   ##
==========================================
+ Coverage   48.83%   49.95%   +1.11%     
==========================================
  Files          63       63              
  Lines        5856     5855       -1     
==========================================
+ Hits         2860     2925      +65     
+ Misses       2996     2930      -66

@belotfa
Copy link
Author

belotfa commented Jan 22, 2020

Build errors all come from a matplotlib backend issue:
ValueError: Format 'jpg' is not supported (supported formats: eps, pdf, pgf, png, ps, raw, rgba, svg, svgz)
It has nothing to do with my changes in code and is probably due to Pillow version (see issue matplotlib/matplotlib#16083).


if CLASS_INDEX is None:
CLASS_INDEX = json.load(open(model_json))
CLASS_INDEX = json.load(open(model_json))
Copy link
Contributor

@rola93 rola93 Feb 7, 2020

Choose a reason for hiding this comment

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

I agree current implementation is not the best. However, this alternative isn't that better: each invocation on it will load exactly the same json.

If will let this change, should at least add a with block to make sure the file is closed properly:

with open(model_json) as f:
    CLASS_INDEX = json.load(f)

Agree on removing as much global variables as possible.

I don't fully understand why was on a global variable while the filename is a parameter... doesn't make sense for me, maybe I'm not seeing something.

Copy link
Author

Choose a reason for hiding this comment

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

I agree current implementation is not the best. However, this alternative isn't that better: each invocation on it will load exactly the same json.

Yeah but that's my point actually. With several instances of CustomImagePrediction running, each invocation will not load exactly the same json and the global variable CLASS_INDEX prevents us from running these instances at the same time.

I don't fully understand why was on a global variable while the filename is a parameter... doesn't make sense for me, maybe I'm not seeing something.

This implementation is useful in other parts of codes in other "custom_utils.py" where some functions don't give a model_json in their parameters (but I checked, all functions that call this "custom_utils.py" give it).

PS : I may have misunderstood your concern, english is not my first language...

Copy link
Contributor

Choose a reason for hiding this comment

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

My point is tat previous version loaded the file only once. We should go to an implementation with only one file-reading but avoiding the point you mention. A bigger refactor is needed, as I see.

English is not my first language too

thanks for your PR, we need to wait for @OlafenwaMoses now

@rola93
Copy link
Contributor

rola93 commented Feb 7, 2020

with respect to the change in requirements.txt, we should fix versions for every library. must consider this for future releases @OlafenwaMoses

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.

2 participants