transcranial / keras-js

Run Keras models in the browser, with GPU support using WebGL
https://transcranial.github.io/keras-js
MIT License
4.96k stars 501 forks source link

Multiple issues. #102

Open harish2704 opened 6 years ago

harish2704 commented 6 years ago

Hi, First of all, thanks a lot for building such a wonder full project. It is really awesome project.

I successfully ported my pre-trained PyTorch model into Keras and run inside browser using Keras-Js. During the process I found some bugs. I am listing it here otherwise I will forget all them all. Later I shall provide individual PR with more details.

  1. Models with varying length input ( using None in place of dimension ) is not working .
    • This feature is currently not implemented in the codebase.
    • The problem is , there is no documentation saying that, variable length input is not supported. It took me some time to understand this fact.
    • If any one try to run a model with variable input dimention, he will see some un-expected error from ndarray package. Instead of that, we could have provide some decent message saying that it is not supported.
  2. Zeropadding layer has some bugs. Especially if we used it as first layer.
    • Consider the case of running Zeropadding layer as first layer using GPU
    • Input layer will run reshapeTo2D() on input data and forward to Zeropadding layer.
    • Zeropadding layer will again call reshapeTo2DSquare() on input . Now we lost the original shape of that input.
  3. Models with data_format=channels_first is almost seems to broken with latest Keras
    • When I checked, Keras now follows same dimension order for exported data of Conv2D layer irrespective of data_format. Permuting weights array while loading weight is not necessary.
    • I also met lot of other errors while trying to load model with data_format=channels_first. Finally I converted my model into data_format=channels_last and it run successfully.
      1. Reshape layer has some bugs. It will fail if we provide -1 as any of target dimension.
    • For eg: if we provide ( 512, -1 ) as target shape in the model definition , new target shape has to calculated each time while running the layer. otherwise it will fail.
    • If this feature is not supported, better we should document about this limitation