yu4u / convnet-drawer

Python script for illustrating Convolutional Neural Networks (CNN) using Keras-like model definitions
MIT License
596 stars 98 forks source link

Matplotlib_util get an error #5

Open ngenne opened 6 years ago

ngenne commented 6 years ago

Hi there,

I'm getting an error everytime I want to generate the graph into the pdf file:

  File "C:\Users\ngenne\Desktop\PRIVE-Deep-Learning\NIH\chest-xray\convnet_drawer\matplotlib_util.py", line 10, in save_model_to_file
    plt.xlim(model.x, model.x + model.width)

AttributeError: 'Sequential' object has no attribute 'x'

Below my code:

from convnet_drawer.convnet_drawer import Model, Conv2D, MaxPooling2D, Flatten, Dense
from convnet_drawer.keras_util import convert_drawer_model
from convnet_drawer.matplotlib_util import save_model_to_file
from keras.models import Sequential
from convnet_drawer.keras_models import AlexNet

classifier = Sequential()

classifier = Model(input_shape=(1024, 1024, 1))
classifier.add(Conv2D(512, (256,256), strides=(4, 4), padding="same"))
classifier.add(MaxPooling2D(pool_size=(2, 2)))
classifier.add(Conv2D(512, (256,256), strides=(4, 4), padding="same"))
classifier.add(Conv2D(512, (256,256), strides=(4, 4), padding="same"))
classifier.add(MaxPooling2D(pool_size=(2, 2)))
classifier.add(Flatten())
classifier.add(Dense(4096))
classifier.add(Dense(4096))
classifier.add(Dense(1000))

classifier = AlexNet.get_model()
classifier_seq = convert_drawer_model(classifier)

Do you have a trick for me?

yu4u commented 6 years ago

Please carefully read examples. You do not need to use Keras APIs.

from convnet_drawer import Model, Conv2D, MaxPooling2D, Flatten, Dense
from matplotlib_util import save_model_to_file

classifier = Model(input_shape=(1024, 1024, 1))
classifier.add(Conv2D(512, (256,256), strides=(4, 4), padding="same"))
classifier.add(MaxPooling2D(pool_size=(2, 2)))
classifier.add(Conv2D(512, (256,256), strides=(4, 4), padding="same"))
classifier.add(Conv2D(512, (256,256), strides=(4, 4), padding="same"))
classifier.add(MaxPooling2D(pool_size=(2, 2)))
classifier.add(Flatten())
classifier.add(Dense(4096))
classifier.add(Dense(4096))
classifier.add(Dense(1000))
save_model_to_file(classifier, "example.pdf")

The above code is enough. But conv256x256 is not expected (usually 3x3 - 11x11) thus the resulting image seems to be broken.