yu4u / convnet-drawer

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

Export PPTX issue/question #16

Closed interactivetech closed 4 years ago

interactivetech commented 5 years ago

Hi there,

Thanks for making this great project! I am interested in using the project to export CNN diagrams in powerpoint, however I am running into an issue I was wondering if you maybe know how to troubleshoot.

I downloaded AlexNet.pptx from your repo and the graph looks like its not being rendered on the powerpoint correctly, here is a screenshot of what I am seeing in powerpoint:

image

It seems that the render location is going beyond the white region area, and going off the slides. Is this an issue on my powerpoint file, or do I have to offset the location in order to have the diagram rendered correctly.

When I export it to jpg, the rendering issue exists. AlexNet

Please advise if you need more information, and I look forward to your response!

yu4u commented 4 years ago

Sorry for late reply.

It seems that the render location is going beyond the white region area, and going off the slides. Is this an issue on my powerpoint file, or do I have to offset the location in order to have the diagram rendered correctly.

It is expected result. Because, in my use case, I anyway edit the resulting slides (put into the other presentation), the position does not matter. Of course, it can be fixed...

interactivetech commented 4 years ago

Is there an easy way to offset the diagram so that it renders correctly? I am interested in developing a system that generate many CNN diagrams, so manually generating a diagram and copying it over to a new presentation would be infeasible in my use case.

yu4u commented 4 years ago

I see. I added shift and scale option for save_model_to_pptx function. https://github.com/yu4u/convnet-drawer/commit/385e8f1d055e1ba65ad84e460e1a2cc2f21167de

You can use this options like this (modification from examples/AlexNet.py. I'm not sure this is enough for your purpose.

import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from convnet_drawer import Model, Conv2D, MaxPooling2D, Flatten, Dense
from pptx_util import save_model_to_pptx

def main():
    model = Model(input_shape=(227, 227, 3))
    model.add(Conv2D(96, (11, 11), (4, 4)))
    model.add(MaxPooling2D((3, 3), strides=(2, 2)))
    model.add(Conv2D(256, (5, 5), padding="same"))
    model.add(MaxPooling2D((3, 3), strides=(2, 2)))
    model.add(Conv2D(384, (3, 3), padding="same"))
    model.add(Conv2D(384, (3, 3), padding="same"))
    model.add(Conv2D(256, (3, 3), padding="same"))
    model.add(MaxPooling2D((3, 3), strides=(2, 2)))
    model.add(Flatten())
    model.add(Dense(4096))
    model.add(Dense(4096))
    model.add(Dense(1000))
    model.save_fig(os.path.splitext(os.path.basename(__file__))[0] + ".svg")
    save_model_to_pptx(model, os.path.splitext(os.path.basename(__file__))[0] + ".pptx", shift=200, scale=0.5)

if __name__ == '__main__':
    main()

image

interactivetech commented 4 years ago

Amazing, thank you for the help! What is the x and y coordinate range for python-pptx?, is it like 800 width and 600 height, or does it depend on the dpi? Any additional information I can read to understand the coordinate system would be great!

yu4u commented 4 years ago

The unit of x and y is Pt: https://github.com/yu4u/convnet-drawer/blob/master/pptx_util.py#L28 The size of presentation is defined by the default of Powerpoint.