waleedka / hiddenlayer

Neural network graphs and training metrics for PyTorch, Tensorflow, and Keras.
MIT License
1.79k stars 266 forks source link

UnboundLocalError: local variable 'FRAMEWORK_TRANSFORMS' referenced before assignment #19

Closed jiaobingle closed 5 years ago

jiaobingle commented 5 years ago

when building a graph with "hl.build_graph(model)" ,model is a tensorflow net, it occurs:

hiddenlayer-master/hiddenlayer/graph.py in build_graph(model, args, input_names, transforms, framework_transforms) 147 if framework_transforms: 148 if framework_transforms == "default": --> 149 framework_transforms = FRAMEWORK_TRANSFORMS 150 for t in framework_transforms: 151 g = t.apply(g)

UnboundLocalError: local variable 'FRAMEWORK_TRANSFORMS' referenced before assignment

philferriere commented 5 years ago

HiddenLayer tries to guess which deep learning framework you are using by calling the following code:

    # Detect framwork
    framework = detect_framework(model)
    if framework == "torch":
        from .pytorch_builder import import_graph, FRAMEWORK_TRANSFORMS
        assert args is not None, "Argument args must be provided for Pytorch models."
        import_graph(g, model, args)
    elif framework == "tensorflow":
        from .tf_builder import import_graph, FRAMEWORK_TRANSFORMS
        import_graph(g, model)

Clearly, if it can't detect which you are using (of PyTorch or TF), then you're in trouble. since there is no "third branch" that will warn you that the framework detection failed. The right thing for us to do, for sure, is to at least tell you that detection failed by raising a warning.

To detect the framework, we inspect the model you pass in, as shown below:

def detect_framework(value):
    classes = (value.__class__,) + value.__class__.__bases__
    for c in classes:
        if c.__module__.startswith("torch"):
            return "torch"
        elif c.__module__.startswith("tensorflow"):
            return "tensorflow"

Frankly, It is quite remarkable that the test would fail... unless you instantiated the model in a somewhat unconventional way (or a way we just simply did not anticipate). The only way for us to help you further is to take a look at the code. Would you mind submitting a minimal working example to help us get to the bottom of this? Once you've done so, feel free to re-open this issue.