Skip to content

Conversation

@rhsimplex
Copy link
Contributor

@josh for discussion - minimal delta for the configuration change w.r.t. #10

@codecov-io
Copy link

codecov-io commented Jun 13, 2017

Codecov Report

Merging #21 into master will decrease coverage by 2.82%.
The diff coverage is 91.19%.

@@           Coverage Diff           @@
##           master   #21      +/-   ##
=======================================
- Coverage   92.82%   90%   -2.83%     
=======================================
  Files          11    12       +1     
  Lines         516   500      -16     
=======================================
- Hits          479   450      -29     
- Misses         37    50      +13

@jwayne
Copy link

jwayne commented Jun 13, 2017

This looks great to me. I just made some small modifications (~15min) to get this branch running on the following examples. I've manually tested that all visualizations work for these examples.

FLASK_APP=picasso PICASSO_SETTINGS=examples/keras/config.py flask run
FLASK_APP=picasso PICASSO_SETTINGS=examples/tensorflow/config.py flask run

Let's review this now! And I'd say, let's not worry about documentation or the codecov report for now - we can fix that in separate PR's that we'll merge into this branch.

class TestTensorflowBackend:
from picasso.ml_frameworks.tensorflow.model import TFModel
class TFTestModel(TFModel):
TF_PREDICT_VAR = 'Softmax:0'
Copy link
Contributor Author

@rhsimplex rhsimplex Jun 14, 2017

Choose a reason for hiding this comment

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

this overrides the configuration file


class TensorflowMNISTModel(TFModel):

TF_INPUT_VAR = 'convolution2d_input_1:0'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is configuration and shouldn't be overridden here

@jwayne
Copy link

jwayne commented Jun 14, 2017

@rhsimplex I saw you made a few updates:

  1. In KerasModel, convert self.tf_predict_var, self.tf_input_var to lower case
  2. In TFModel, convert class attributes TF_PREDICT_VAR, TF_INPUT_VAR to lower-case. Use
    these class attributes' values unless the arguments tf_predict_var, tf_input_var are passed into the constructor, in which we override them with the arguments' values.

I agree with (1) because these attributes are set in an instance method (specifically, the instance constructor), which makes them class attributes. Thus, they should be lower case. Furthermore, in TFModel, these are lower-case attributes, and these attributes should be named the same way in TFModel and KerasModel. (The notion that these attributes should have the same name in TFModel and KerasModel will be clearer when we convert tf_predict_var, tf_input_var to properties in a shared interface)

I disagree with (2) for 2 reasons. Aside from breaking the convention that class attributes be upper-case, more importantly, it is bad style to override class attributes in an instance. Class attributes belong to the class, so generally users expect that they are untouched by an instance. Instances should only modify instance attributes, which they own. In this particular case, I'd recommend converting the class attributes' names back to upper case and then defining the TFModel constructor as follows:

def __init__(self, *args, **kwargs):
    super(TFModel, self).__init__(*args, **kwargs)
    if not hasattr(self, 'tf_predict_var'):
        self.tf_predict_var = self.TF_PREDICT_VAR
    if not hasattr(self, 'tf_input_var'):
        self.tf_input_var = self.TF_INPUT_VAR

Now, this is still bad style, since generally we shouldn't be using hasattr checks. But we can fix this in the separate formatting/styling PR.

@jan-xyz
Copy link
Contributor

jan-xyz commented Jun 15, 2017

@jwayne, I'm assuming you are using PEP8 code style in picasso.

According to PEP8 all caps is reserved for constants not for class variables. Class variables should lead with a double under score (e.g. __tf_predict_value) and they can be accessed by calling the base class directly since python doesn't import variables with that naming scheme automatically (e.g. baseModel.__tf_predict_model).

here the reference to the section in PEP8: https://www.python.org/dev/peps/pep-0008/#method-names-and-instance-variables

another question: why are you not specifying the parameters for the models? In my opinion using *args and **kwargs obfuscates and reduces readability. Furthermore you could shorten the entire logic by using default parameters directly:

def __init__(self, 
             tf_predict_var=BaseModel.__tf_predit_var,
             tf_input_var=BaseModel.__tf_input_var):
    super(TFModel, self).__init__(*args, **kwargs)
    self.tf_predict_var = tf_predict_var
    self.tf_input_var = tf_input_var

@rhsimplex
Copy link
Contributor Author

rhsimplex commented Jun 15, 2017

@jwayne @jan-xyz I agree the casing is not correct! But since I'm trying for the minimal delta for the current feature, and they are upper case and lower case throughout the code, I just changed them all to the same case to make the test pass (since the visualizations refer to the lower-case versions).

We're doing another PR with style changes on top of this one, we can fix it there if that's alright (and even merge it in to this one before merging to master).

EDIT @jwayne haha i see you said the same thing in the last sentence of your post. I should read more.

@jwayne
Copy link

jwayne commented Jun 15, 2017 via email

@jwayne
Copy link

jwayne commented Jun 15, 2017 via email

@rhsimplex
Copy link
Contributor Author

If it looks ok to you @jwayne, then I'll update the documentation and merge (or leave this branch separate for now, whichever you prefer).

@jwayne jwayne force-pushed the class-config branch 3 times, most recently from c1667d6 to a7c7255 Compare July 5, 2017 13:58
@jwayne
Copy link

jwayne commented Jul 5, 2017

@rhsimplex I finished making the code style and formatting changes in the last 2 commits. I'd recommend looking at them independently. I think they should be relatively parseable, let me know and thanks!

' setting. The settings and utility functions'
' have been changed as of version v0.2.0 (and '
'you\'re using {}). Changing to the updated '
' settings is trivial: see xxxxxxx.'.format(__version__))
Copy link

@jwayne jwayne Jul 6, 2017

Choose a reason for hiding this comment

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

remember to update the xxxxx

'BACKEND_POSTPROCESSOR_NAME',
'BACKEND_POSTPROCESSOR_PATH',
'BACKEND_PROB_DECODER_NAME',
'BACKEND_PROB_DECODER_PATH']
Copy link

@jwayne jwayne Jul 6, 2017

Choose a reason for hiding this comment

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

probably want to add DATA_DIR here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch

@rhsimplex rhsimplex merged commit 1d396da into master Jul 7, 2017
@rhsimplex rhsimplex deleted the class-config branch July 7, 2017 09:06
rhsimplex added a commit that referenced this pull request Jul 7, 2017
This reverts commit 1d396da.
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.

5 participants