-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lj1ang <[email protected]>
- Loading branch information
Showing
3 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
- [Implement Sedna Python SDK support TinyMS](#mplement Sedna Python SDK support TinyMS) | ||
- [Motivation](#Motivation) | ||
- [Goals](#Goals) | ||
- [Proposal](#Proposal) | ||
- [Sedna Architecture analysis](#Sedna Architecture analysis) | ||
- [Feasibility](#Feasibility) | ||
- [Design Details](#Design Details) | ||
- [set_backend()](#set_backend() ) | ||
- [TInyMS API](#TInyMS API) | ||
- [Demo Based on MSBackend](#Based on MSBackend) | ||
- [Demo Based on TinyMSBackend](#Based on MSBackend) | ||
- [Road Map](#Road Map) | ||
|
||
# Implement Sedna Python SDK support TinyMS | ||
|
||
## Motivation | ||
|
||
Currently, Sedna only supports sklearn's xgboost, Tensorflow, Keras, PyTorch and MindSpore, but doesn’t support MindSpore’s high-level API tool TinyMS. | ||
|
||
This proposal aims to implement Senda Python SDK ‘s support for TinyMS based on Sedna's lib development interface and implements an Incremental Learning demo. | ||
|
||
### Goals | ||
|
||
- Implement Sedna Python SDK support of TinyMS | ||
- Write user guide document of TinyMS | ||
|
||
## Proposal | ||
|
||
### Sedna Architecture analysis | ||
|
||
![](./images/tinyms-support-architecture.png) | ||
|
||
Taking the case yolo3 incremental learning in Sedna as an example, the user wraps the estimator for the specific model. when the incremental learning interface `IncrementalLearning()` is called, the following process takes place: | ||
|
||
- IncrementalLearning instantiates its parent class JobBase. | ||
- Call `set_backend()` in the constructor of JobBase to resolve the framework used by the model to TensorFlow and instantiate the corresponding TFBackend. | ||
|
||
- TFBackend inherits BackendBase, which is initialized with OS-related configuration when instantiated. | ||
|
||
- TFBackend implements the specific framework-related configuration. | ||
|
||
### Feasibility | ||
|
||
Sedna parses the underlying framework of the model and runs the model using a different machine learning framework through a backend pair. So we need to : | ||
|
||
- implement Sedna's parsing of the underlying machining learning framework | ||
|
||
![](./images/tinyms-support-set_bakcend.png) | ||
|
||
- implement TinyMSBackend | ||
|
||
# Design Details | ||
|
||
## set_backend() | ||
|
||
Improve function `set_backend()` in `sedna/backend/__init__.py` | ||
|
||
```python | ||
if backend_type == "TINYMS": | ||
from sedna.backend.tinyms import TinyMSBackend as REGISTER | ||
``` | ||
|
||
## TInyMS API | ||
|
||
TinyMS is MindSpore's high-level API, but the TinyMS’s methods are not the same as the MindSpore framework’s , so we can not use the idea of inheritance for encapsulation. | ||
|
||
`TinyMSBackend`class | ||
|
||
- `__init__(self, estimator, fine_tune=True, **kwargs) ` :initialize | ||
|
||
- `train(self, train_data, valid_data=None, **kwargs)`: train the model | ||
|
||
- `predict(self, data, **kwargs) `: use the model to preidct result | ||
|
||
- `evaluate(self, data, **kwargs)`: evaluate the accuracy | ||
|
||
- `load_weights(self)`: load model weight | ||
|
||
- `get_weights(self) `:return weight | ||
|
||
- `set_weights(self, weights) `:set weight | ||
|
||
```python | ||
class TinyMSBackend(MSBackend): | ||
def __init__(self, estimator, fine_tune=True, **kwargs): | ||
... | ||
|
||
def train(self, train_data, valid_data=None, **kwargs): | ||
... | ||
|
||
def predict(self, data, **kwargs): | ||
... | ||
|
||
def evaluate(self, valid_data, **kwargs): | ||
... | ||
|
||
def save(self, model_path=None): | ||
... | ||
|
||
def load(self, model_url=""): | ||
... | ||
|
||
def load_weights(self): | ||
... | ||
|
||
def get_weights(self): | ||
... | ||
|
||
def set_weights(self, weights): | ||
... | ||
``` | ||
|
||
## Demo Based on MSBackend | ||
|
||
- [implement MobileNetV2 with MindSpore](https://www.mindspore.cn/tutorial/zh-CN/r0.7/advanced_use/mobilenetv2_incremental_learning.html) | ||
|
||
- Build an estimator class based on MobileNetV2, encapsulating a series of methods such as `train(),evaluate(),predict()`, etc. | ||
- Call incremental learning API to accomplish model training, evaluation, and inference | ||
|
||
## Demo Based on TinyMSBackend | ||
|
||
- [implement MobileNetV2 with TinyMS](https://tinyms.readthedocs.io/en/latest/tutorials/ipynb/TinyMS_MobileNetV2_tutorial.html) | ||
|
||
- Build an estimator class based on MobileNetV2, encapsulating a series of methods such as `train(),evaluate(),predict()`, etc. | ||
|
||
- Call incremental learning API to accomplish model training, evaluation and inference | ||
|
||
# Road Map | ||
|
||
- Implementing an incremental learning demo based on MSBackend | ||
- [ ] week1 : implement `estimator` | ||
- [ ] week2 : debug model | ||
|
||
- TinyMS(08/8-09/16) | ||
|
||
- [ ] week3 : learn `TinyMS`documentation | ||
- [ ] week4 : implement `TinyMSBackend` class | ||
- [ ] week5 : implement `estimator` | ||
- [ ] week6 : debug model | ||
|
||
- Write documentation(09/17-09/30) | ||
|
||
- [ ] week7 : write API documentation | ||
- [ ] week8 : write demo documentation and submit PR |