Skip to content

itrm-team/oceanai-py

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 

banner

Oceanai-py

Wrapper library that allows a direct integration between the Ocean marketplace and artificial intelligence tools like tensorflow

With Oceanai-py, you can:

  • Create artificial intelligence models: the current state of the library uses Tensorflow for the implementation of the AI models, anything that you can do with Tensorflow you can also do it with Oceanai-py

  • Buy OCEAN marketplace datasets to use them on your models

  • Consume OCEAN datatokens, to access the services of the Ocean environment.

Every function related to the OCEAN environment is fullfiled using Ocean.py. Ocean.py is part of the Ocean Protocol toolset.

This library is still in alpha state and you can expect running into problems.

πŸ“š Prerequisites

πŸ— Installation

#Is necesary to install tensorflow  and ocean-lib separately to avoid download errors.
pip install oceanai-py
pip install tensorflow
pip install --pre ocean-lib

πŸ„ Quickstart

The source code of this example is also included on the folder samples of the library

index.py This file explains how to implement several types of AI models for the selected Ocean dataset

import tensorflow as tf
from model_goal import ModelGoal
from src.ia.tensorflow_s.sequential_space import SequentialSpace
from src.ia.tensorflow_s.models.multilayer.multilayer_dataset_parser import MultilayerDataParser
from src.ia.tensorflow_s.multilevel.multilevel_sequential_training import MultilevelSequentialTraining

inputs = [
    [ 0.1, 0.3, 0.4, 0.4 ],
    [ 0.8, 0.2, 0.2, 0.6 ],
    [ 0.2, 0.6, 0.4, 0.3 ],
    [ 0.3, 0.8, 0.7, 0.9 ],
    [ 0.1, 0.2, 0.3, 0.2 ],
    [ 0.4, 0.4, 0.9, 0.1 ],
    [ 0.1, 0.3, 0.2, 0.5 ],
    [ 0.5, 0.5, 0.3, 0.3 ],
    [ 0.7, 0.6, 0.2, 0.5 ],
    ]

outputs = [
    [ 0.25, 0.4  ],
    [ 0.5,  0.4  ],
    [ 0.5,  0.35 ],
    [ 0.55, 0.8  ],
    [ 0.15, 0.25 ],
    [ 0.4,  0.5  ],
    [ 0.4,  0.35 ],
    [ 0.5,  0.3  ],
    [ 0.65, 0.35 ],
    ]

args = {
    "inputs": 4,
    "outputs": 2,
    "hidden": [20, 20]
    }

compileArgs = {
    'optimizer': tf.keras.optimizers.Adamax(learning_rate=1e-3),
    'loss': tf.keras.losses.MeanSquaredError(),
    'metrics': [tf.keras.metrics.MeanSquaredError()]
}

fitArgs = {
    'epochs': 100,
    'batchSize': 32
}

iters = 10

goal = ModelGoal(inputs, outputs)

def sample():
    layers = [
        tf.keras.layers.Dense(units=args['inputs'], input_shape=(args['inputs'],)), # input layer
        tf.keras.layers.Dense(units=20 ), # hidden layer 1
        tf.keras.layers.Dense(units=20 ), # hidden layer 2
        tf.keras.layers.Dense(units=args["outputs"]) # output layer
        ]
    space = SequentialSpace(layers)
    parser =  MultilayerDataParser(2)
    training = MultilevelSequentialTraining(goal, parser, compileArgs, fitArgs,iters)
    model = training.apply(space)
    print('> outputs: '+str(outputs))
    print("> predictions: "+str(model.apply(inputs)))
    

sample()

Obtaining Ocean datasets

In here we will explain how to obtain OCEAN datasets using oceanai-lib.

from src.ocean.occean import Occean

d = {
   'network' : 'https://rinkeby.infura.io/v3/proyectid',
   'metadataCacheUri' : 'https://v4.aquarius.oceanprotocol.com',
   'providerUri' : 'https://v4.provider.rinkeby.oceanprotocol.com',
}

occean = Occean(d,"private key my account","private key accout buying from")

# create NFT token in the accoutn buying from
data_nft = occean.publishNFTToken('NFTToken1', 'NFT1')
##occean.createDatasetExmple()
# the account we are buying from create the datatoken 
datatoken = occean.createDataToken(data_nft,2)
#datatoken = occean.getDatatoken('token address') we can allso get the datatoken 
#creat exage id an the buy
exange_id = occean.getExchangeId(datatoken,1,3)
tx_result = occean.buy(datatoken,exange_id,1,2)

πŸ“– Learn more

⬆️ Releases

Coming soon.

πŸ› License

Copyright ((C)) 2021 Intelligent Trading Machines

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

Repository for the implementation of oceanai library in python version

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages