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

Add documentation for loading keras models #2005

Merged
merged 21 commits into from Dec 15, 2017

Conversation

hkvision
Copy link
Contributor

What changes were proposed in this pull request?

Add doc for keras model loading.

@@ -0,0 +1,24 @@
# **Keras Support**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

related issue: #1987

Copy link
Contributor

@yiheng yiheng Dec 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep it here just like tf support/caffe support. That issue is not related with this PR.

@hkvision
Copy link
Contributor Author

@jason-dai any comments on the doc?

keras_model.add(Activation('relu'))
keras_model.add(Dropout(0.5))
keras_model.add(Dense(10))
keras_model.add(Activation('softmax'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use LogSoftMax together with ClassNLL, or we can refactor this later after this PR (#1944 )merged

def_path = "lenet.json"
with open(def_path, "w") as json_file:
json_file.write(model_json)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Divide this into 3 : 1) Pure keras model definition + data processing 2) save keras model 3)load keras model and train with BigDL optimizer. Maybe extract 3 methods to make your intention more clear.

model=bigdl_model,
training_rdd=train_data,
criterion=ClassNLLCriterion(),
optim_method=SGD(learningrate=0.01),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tunning this?


__Remark__: Packages `tensorflow`, `keras==1.2.2` and `h5py` are required. They can be installed via `pip` easily.

```python
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scala API example?


You can directly use the API `load_keras` to load the Keras model into BigDL.

__Remark__: Packages `tensorflow`, `keras==1.2.2` and `h5py` are required. They can be installed via `pip` easily.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why tensorflow is required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tensorflow is the backend used by keras

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is one of the backend. For keras model save/load, I don't think we need tensorflow


You can directly use the API `load_keras` to load the Keras model into BigDL.

__Remark__: Packages `tensorflow`, `keras==1.2.2` and `h5py` are required. They can be installed via `pip` easily.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need tensorflow?


__Remark__: Packages `tensorflow`, `keras==1.2.2` and `h5py` are required. They can be installed via `pip` easily.

```python
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is the scala example?

### **Limitations**
We have tested the model loading functionality with several standard [Keras applications](https://faroit.github.io/keras-docs/1.2.2/applications/) and [examples](https://github.com/fchollet/keras/tree/1.2.2/examples).

However, there still exist some arguments for Keras layers that are not supported in BigDL for now. Also we haven't supported self-defined Keras layers, but one can still define your customized layer converter and weight converter method for new layers if you wish.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create a page provide the list of keras layer we have supported? like this: https://github.com/tf-coreml/tf-coreml#supported-ops

Copy link
Contributor

@yiheng yiheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check my comments

@hkvision
Copy link
Contributor Author

jenkins passed http://172.168.2.101:8080/job/BigDL-PR-V/532/

@hkvision
Copy link
Contributor Author

hkvision commented Dec 14, 2017

Due to the limitation of our implementation, loading a keras model into BigDL need to rely on keras (mainly used for the calculation of input shape). In other words, if users need to use this functionality, they need to install keras 1.2.2 beforehand. tensorflow is not required now. Keras can use theano as backend as well. Tested with using theano to load a keras model. In addition, the API is only available on Python side. cc @yiheng @zhichao-li @jason-dai

@hkvision
Copy link
Contributor Author

Since keras needs a backend to construct the model, in the future we may consider using bigdl backend (only implement the minimum necessary methods) as suggested by Jason.

@yiheng
Copy link
Contributor

yiheng commented Dec 14, 2017

LGTM

1 similar comment
@jason-dai
Copy link
Contributor

LGTM

@hkvision hkvision merged commit 84f453b into intel-analytics:master Dec 15, 2017
Le-Zheng pushed a commit to Le-Zheng/BigDL that referenced this pull request Oct 20, 2021
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

Successfully merging this pull request may close these issues.

None yet

4 participants