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

plot_model throws AssertionError #12640

Closed
3 tasks done
devedse opened this issue Apr 8, 2019 · 5 comments
Closed
3 tasks done

plot_model throws AssertionError #12640

devedse opened this issue Apr 8, 2019 · 5 comments
Assignees

Comments

@devedse
Copy link

devedse commented Apr 8, 2019

Please make sure that the boxes below are checked before you submit your issue.
If your issue is an implementation question, please ask your question on StackOverflow or on the Keras Slack channel instead of opening a GitHub issue.

Thank you!

  • Check that you are up-to-date with the master branch of Keras. You can update with:
    pip install git+git://github.com/keras-team/keras.git --upgrade --no-deps

  • Check that your version of TensorFlow is up-to-date. The installation instructions can be found here.

  • Provide a link to a GitHub Gist of a Python script that can reproduce your issue (or just copy the script here if it is short).

Introduction

I'm currently following the Plural Sight course on setting up Keras and using it for Object Detection. However with the second script I'm running into an AssertionError:

image

Code used for the course:

#   deep_circles.py
#   Defines a network that can find separate circles of data
#

#   Imports
from sklearn.datasets import make_circles
import numpy as np
import matplotlib.pyplot as plt
import os
os.environ["TF_CPP_MIN_LOG_LEVEL"]="2"

#   Helper functions

#   plot the data on a figure
def plot_data(pl, X, y):
    # plot class where y==0
    pl.plot(X[y==0, 0], X[y==0,1], 'ob', alpha=0.5)
    # plot class where y==1
    pl.plot(X[y==1, 0], X[y==1,1], 'xr', alpha=0.5)
    pl.legend(['0', '1'])
    return pl

#   Common function that draws the decision boundaries
def plot_decision_boundary(model, X, y):

    amin, bmin = X.min(axis=0) - 0.1
    amax, bmax = X.max(axis=0) + 0.1
    hticks = np.linspace(amin, amax, 101)
    vticks = np.linspace(bmin, bmax, 101)
    
    aa, bb = np.meshgrid(hticks, vticks)
    ab = np.c_[aa.ravel(), bb.ravel()]
    
    # make prediction with the model and reshape the output so contourf can plot it
    c = model.predict(ab)
    Z = c.reshape(aa.shape)

    plt.figure(figsize=(12, 8))
    # plot the contour
    plt.contourf(aa, bb, Z, cmap='bwr', alpha=0.2)
    # plot the moons of data
    plot_data(plt, X, y)

    return plt


# Generate some data blobs.  Data will be either 0 or 1 when 2 is number of centers.
# X is a [number of samples, 2] sized array. X[sample] contains its x,y position of the sample in the space
# ex: X[1] = [1.342, -2.3], X[2] = [-4.342, 2.12]
# y is a [number of samples] sized array. y[sample] contains the class index (ie. 0 or 1 when there are 2 centers)
# ex: y[1] = 0 , y[1] = 1
X, y = make_circles(n_samples=1000, factor=.6, noise=0.1, random_state=42)
#pl = plot_data(plt, X, y)
#pl.show()

# Split the data into Training and Test sets
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)

# Create the keras model
from keras.models import Sequential
from keras.layers import Dense
from keras.optimizers import Adam

#   Simple Sequential model
model = Sequential()
model.add(Dense(4, input_shape=(2,), activation="tanh", name="Hidden-1"))
model.add(Dense(4, activation="tanh", name="Hidden-2"))
#   Add a Dense Fully Connected Layer with 1 neuron.  Using input_shape = (2,) says the input will 
#       be arrays of the form (*,2).  The first dimension will be an unspecified 
#       number of batches (rows) of data.  The second dimension is 2 which are the X, Y positions of each data element.
#       The sigmoid activation function is used to return 0 or 1, signifying the data 
#       cluster the position is predicted to belong to.
model.add(Dense(1, activation="sigmoid", name="output_layer"))
model.summary()
#   Compile the model.  Minimize crossentopy for a binary.  Maximize for accuracy
model.compile(Adam(lr=0.05), 'binary_crossentropy', metrics=['accuracy'])
from keras.utils import plot_model
plot_model(model, to_file="model.png", show_shapes=True, show_layer_names=True)

# The line above here fails




#   Define early stopping callback
from keras.callbacks import EarlyStopping
my_callbacks = [EarlyStopping(monitor='val_acc', patience=5, mode='max')]
#   Fit the model with the data from make_blobs.  Make 100 cycles through the data.
#       Set verbose to 0 to supress progress messages 
model.fit(X_train, y_train, epochs=100, verbose=1, callbacks=my_callbacks, validation_data=(X_test, y_test))
#   Get loss and accuracy on test data
eval_result = model.evaluate(X_test, y_test)
#   Print test accuracy
print("\n\nTest loss:", eval_result[0], "Test accuracy:", eval_result[1])
#   Plot the decision boundary
plot_decision_boundary(model, X, y).show()

There's already a duplicate of this issue but it was closed without a fix: #12538

I mean honestly wtf, hacking code into the Keras library without actually commiting it != a fix 😄

@ymodak, you asked for a way to reproduce this error. All this information should be enough for this.

My environment

OS: Windows 10
Python install: MiniConda with 3.6
CUDA: Yes

Commands I ran:

conda create -n POMP2 python=3.6
activate POMP2

conda install tensorflow-gpu
conda install keras

conda install scikit-learn matplotlib pydot

Note: graphviz is automatically installed.

My investigation

I already tried to figure out what's going on and it seems that at some point a file named dot.bat is called which returned exit code 1.

Path of dot.bat: C:\Users\******\AppData\Local\conda\conda\pkgs\graphviz-2.38-hfd603c8_2\Library\bin\dot.bat

If I check out that file it calls dot.exe
Path of dot.exe: C:\Users\********\AppData\Local\conda\conda\pkgs\graphviz-2.38-hfd603c8_2\Library\bin\graphviz\dot.exe

When you check out the screenshot, you can see on the bottom the commands that are being used to call dot.bat:

['dot.bat', '-Tps', 'C:\\Users\\********\\AppData\\Local\\Temp\\tmpd7q3ltxy'] return code: 1

If I however check the Temp directory to see if there's a file named tmpd7q3ltxy. There is none.

Question

Does anyone have any idea what's going on here?

@Anurag14
Copy link

Anurag14 commented May 4, 2019

Just to add to this, I am also facing the same issue. Is any working solution/workaround available yet?

@jvishnuvardhan jvishnuvardhan self-assigned this Jul 27, 2019
@LucaAmerio
Copy link

Same issue here

@Raazzta
Copy link

Raazzta commented Feb 27, 2020

my case, I modify layer's name and it works. I think it's because of layer's name

@sandeepnmenon
Copy link

+1
same issue

@LucaAmerio
Copy link

Try this fix pydot/pydot#222

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

No branches or pull requests

8 participants