# Week 2 ( Acumos ) Note
## Name : Christofel Rio Goenawan
## University : Bandung Institute of Technology (ITB)
## Date : 13/3/2020 - 18/3/2020
## Objectives:
1. Understand concept and work of Acumos Platform. (What? How? Why ? )
2. Know how to onboard ML model on Acumos.
## 1. What is Acumos Platform?
Acumos is a **collaborative framework** that is easy to **build , share and deploy AI apps** and works by **linux Foundation**.This framework used to form a **distributed AI Marketplace** also its community, that is enable the **packaging, cataloging, and sharing of AI models** . This platform can simplify Machine Learning model training, evaluation and deployment.
## 2. How Acumos Platform works?
In simple term Acumos Platform can be shown by figure below.

In more complete term the works can be shown by figure below.

The picture above is showing how the acumos platform works.
There are developer who make the machine learning model that will be uploaded to the platform. These uploaded model will enter the marketplace. In this marketplace, these model can be trained using dataset. They can be published and deployed to some system.
## 3. Why using Acumos Platform?
As explained above , Acumos platform offer a lot of ease in build, share and deploy ML models. Hence Acumos can be used to grow awareness of AI/Machine Learning/Deep learning as software tools. Because with Acumos, End Users from any background can use AI without special knowledge on AI.
Because acumos is a distributed AI Marketplace, it can reduce redundancy and increase communication.
## 4. Installing Acumos Platform
For installing Acumos Paltform on PC first we need to fulfill some PC sepesification as below.

Then we can install the Acumos platform by using this guidelines:
https://wiki.acumos.org/display/AC/Acumos+Installation
*Note : Writer got problem in installing the Acumos Platform because writer's PC doesn't fulfill the minimum spesification and using Windows OS, not Linux.
Solution:
1. Using virtual machine to run linux based platform. (preferd)
2. Writer change OS to Linux.*
## 5. Onboard ML Model to Acumos
### Prerequisite
Before onboarding ML model to Acumos, we have to setup the requirement first. As a model onboarder we need to have a web browser, python version 3.4 or higher, Acumos Client Library, Protocol Buffer (Protobuff), ML package of choice.
As a Model user, we need to have web browser, python, protobuf and Requests (Python Package)
### 5.1. Setting Up Acumos Client
I use anaconda to set my python environtment. First of all, i install the acumos client library using Anaconda prompt. What we need to do is type this command then hit enter.
` pip install acumos `
But because I am using python in my Windows OS, I instead use the syntax below.
` py -m pip install acumos`
After we hit the enter, the installation process will proceed. Here is what will we see in the prompt.

The installation is already finished when you see your cursor again.
### 5.2. Setting-up Protocol Buffers
Acumos package uses protocol buffers so we should install protobuf compiler protoc. To install the protoc from anaconda prompt we need to type this line.
`code install -c anaconda libprotobuf`
Then the prompt will shown as below.

Then we need to type 'y' to continue the process as below.

This installation might include some other update in the anaconda environtment. In my case, it includes my conda version update from version 4.8.2 to 4.8.3.
### 5.3. Make an Example Model
In our first onboarding to acumos, we use an example model which is obtained from the reference. This code is a Python scikit-learn model which is lifted directly from the example given on pypi.org/project/acumos/
```Python
from acumos.session import AcumosSession
from acumos.modeling import Model, List, create_dataframe
import numpy as np
import pandas as pd
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
iris = load_iris()
X = iris.data
y = iris.target
clf = RandomForestClassifier(random_state=0)
clf.fit(X, y)
# here, an appropriate NamedTuple type is inferred from a pandas DataFrame
X_df = pd.DataFrame(X, columns=['sepal_length', 'sepal_width', 'petal_length', 'petal_width'])
IrisDataFrame = create_dataframe('IrisDataFrame', X_df)
# ==================================================================================
# # or equivalently:
#
# IrisDataFrame = create_namedtuple('IrisDataFrame', [('sepal_length', List[float]),
# ('sepal_width', List[float]),
# ('petal_length', List[float]),
# ('petal_width', List[float])])
# ==================================================================================
def classify_iris(df: IrisDataFrame) -> List[int]:
'''Returns an array of iris classifications'''
X = np.column_stack(df)
return clf.predict(X)
model = Model(classify=classify_iris)
session = AcumosSession()
session.dump(model,'Iris_sklearn','directory')
```
This code will generate an artifact. This artifact contains 3 files. We will use this artifact for the onboarding process.
I use Visual Code Editor text as a text editor then run the program using command prompt. I encounter some exeption when i run the code. I found that the acumos package import a **GenericMeta** from typing. I use python **version 3.7** that has removed GenericMeta from typing. After googling for a while, i get a clue that we can add this code to handle the ImportError.
```Python
try:
from typing import GenericMeta # python 3.6
except ImportError:
# in 3.7, genericmeta doesn't exist but we don't need it
class GenericMeta(type): pass
```
I get this code from github (https://github.com/hsolbrig/PyShEx/issues/17)
I add this code to acumos sub package pickler.py that use the GenericMeta
After adding the line, i run the model again. But another error/exeption came up. It looks like the acumos need the GenericMeta from typing.py. I asked Febri and Akmal about this issues and he suggests me to use the **google colab** instead of the command line to run the model.
#### Using Google Colab
Using Google Colab I use the exact code as in command prompt as below.

After running the model, I finally get the 3 file for the onboarding that is: **metadata.json, model.proto and model.zip**. Then I use the code like tutorial to download these files.
```Python
from google.colab import files
files.download('/Users/Christofel04/Desktop/Iris_sklearn/metadata.json')
files.download('/Users/Christofel04/Desktop/Iris_sklearn/model.proto')
files.download('/Users/Christofel04/Desktop/Iris_sklearn/model.zip')
```
### 5.4. Onboarding the Model to Acumos Web Platform
When I first came to the website, there is no option for the on boarding. According to the tutorial video, there should be an on boarding access tab in the left menu.
After do some internet search, I found that we need to directly access the onboarding page through this link to get to the on boarding page
https://marketplace.acumos.org/index.html#/modelerResource
After accessing the on boarding page in acumos marketplace web page, i try to on board the model using the web. But i encounter the same problem like Febri , Akmal and Kevin did.

I still trying to find the solution to this problem.
## Sources:
1. https://www.w3.org/2018/Talks/web5g/W3C_Web5G_DanD.pdf
2. https://www.acumos.org/platform/
3. https://wiki.acumos.org/display/AC/Acumos+Installation