-1

It looks like your post is mostly code; please add some more details. I'm trying to train the model and I have this error"Failed to import pydot. Please install pydot. For example with pip install pydot." and I have already install pydot and graphviz,

from keras.utils import print_summary
print_summary(model, line_length=None, positions=None, print_fn=None)

# add some visualization
from IPython.display import SVG
from keras.utils.vis_utils import model_to_dot
SVG(model_to_dot(model).create(prog='dot', format='svg'))



# train the network
print("training network...")
sys.stdout.flush()
#class_mode ='categorical', # 2D one-hot encoded labels
H = model.fit_generator(aug.flow(Xtrain, trainY, batch_size=BS), \
    validation_data=(Xval, valY), \
    steps_per_epoch=len(trainX) // BS, \
    epochs=EPOCHS, verbose=1)

# save the model to disk
print("Saving model to disk")
sys.stdout.flush()
model.save("/tmp/mymodel")


# set the matplotlib backend so figures can be saved in the background
# plot the training loss and accuracy
print("Generating plots...")
sys.stdout.flush()
matplotlib.use("Agg")
matplotlib.pyplot.style.use("ggplot")
matplotlib.pyplot.figure()
N = EPOCHS
matplotlib.pyplot.plot(np.arange(0, N), H.history["loss"], label="train_loss")
matplotlib.pyplot.plot(np.arange(0, N), H.history["val_loss"], label="val_loss")
matplotlib.pyplot.plot(np.arange(0, N), H.history["acc"], label="train_acc")
matplotlib.pyplot.plot(np.arange(0, N), H.history["val_acc"], label="val_acc")
matplotlib.pyplot.title("Training Loss and Accuracy on diabetic retinopathy detection")
matplotlib.pyplot.xlabel("Epoch #")
matplotlib.pyplot.ylabel("Loss/Accuracy")
matplotlib.pyplot.legend(loc="lower left")
matplotlib.pyplot.savefig("plot.png") 


wovano
  • 4,543
  • 5
  • 22
  • 49
wafa
  • 61
  • 1
  • 1
  • 3
  • 2
    Please explain how you're setting up your environment. Anaconda, Python virtual environments, neither of those? There's also some text at the beginning of your question which shouldn't be there, please remove it. – Roland Weber Jun 23 '19 at 07:20
  • yes I have used Anaconda with Spyder editor and I have create an environment called tensor flow and download all required modules – wafa Jun 23 '19 at 09:44
  • 2
    How did you install the required modules? Just downloading them does not solve the problem. And how do you run your application? Please describe this as detailed as possible (the exact commands that you enter), since it's really important. There can be so many causes for this error. And apparently you got a warning that your question is mostly code. Why did you include this specific code? It does not use `pydot` at all, while your error is about `pydot`... See [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) and [mre] to improve your question. – wovano Jun 23 '19 at 11:40
  • Hello @wafa ! I wrote an answer to this question please consider upvoting it and / or marking it as answer to your question if it was useful :) – Pitto Jul 02 '19 at 11:40
  • Make sure you are using the correct virtual env. If you are sure you are, please check that the PYTHONPATH is correct. Also - Spyder might have a separate PYTHONPATH setting different fron the anaconda shell. – LudvigH Aug 06 '19 at 11:20

1 Answers1

1

I think that you are using python 3.

In that case be sure that you installed dependencies for python 3 using pip3 and not for python 2 (using pip).

pip3 install pydot

Pitto
  • 8,229
  • 3
  • 42
  • 51