How to use modelbase - 10 common examples

To help you get started, we’ve selected a few modelbase examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CalvinNeo / EasyMLPlatform / py / ml_models / assessment.py View on Github external
def __init__(self, model, dataset):
        self.model = model
        self.dataset = dataset
        self.TP, self.TN, self.FP, self.FN = 0, 0, 0, 0
        self.Losses = [0.0] * self.dataset.Length()
        '''
            Protoclass in ['REGRESS', 'CLASSFY', 'CLUASTER']
        '''
        self.Protoclass = ModelBase.AllModelInfo()[self.model.prototype]['modeltype']
github uoguelph-mlrg / Theano-MPI / lib / models / googlenet.py View on Github external
softmax_layer = Softmax(input=drp.output ,n_in=1024, n_out=config['n_softmax_out'])
        
        layers.append(softmax_layer)
        params += softmax_layer.params
        weight_types += softmax_layer.weight_type
        
        self.layers = layers
        self.params = params
        self.weight_types = weight_types
        self.output = softmax_layer.p_y_given_x
        self.negative_log_likelihood = softmax_layer.negative_log_likelihood
         
              
    

class GoogLeNet(ModelBase):

    """    GoogleNet classifier for ILSVRC.
    
    Parameters:
    
        config:  dict
        training related and model related hyperparameter dict 
    
    References:
    
        [1] C Szegedy, W Liu, Y Jia, P Sermanet, S Reed, 
            D Anguelov, D Erhan, V Vanhoucke, A Rabinovich (2014):
            Going deeper with convolutions.
            The IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2015, pp. 1-9
            
        [2] https://github.com/BVLC/caffe/tree/master/models/bvlc_googlenet
github CalvinNeo / EasyMLPlatform / py / ml_models / logistic.py View on Github external
#coding:utf8
import sys
sys.path.append('..')

from modelbase import ModelBase
import math
import datasets
from datasets.localdata import *
from datasets.monads import *
import operator
import numpy as np
from collections import defaultdict, namedtuple
import itertools
import pickle

class LogisticRegression(ModelBase):
    '''
        simple Logistic Regression is linear
    '''
    def __init__(self, dataset, classfeatureindex = -1, alpha = 0.2, maxiter = 50, *args, **kwargs):
        ModelBase.__init__(self, dataset, 'LOGISTIC', *args, **kwargs)
        self.classfeatureindex = classfeatureindex #index of the column which defines the feature in dataset
        self.Test = self.Classify2
        self.Apply = self.ClassifyDataset
        self.Train = self.Regress
        self.Save = self.DumpLogistic
        self.Load = self.LoadLogistic
        self.Graph = self.ShowImage
        self.Positive = 1
        self.Negative = -1
        # use default
        # self.T = self.RealValue
github CalvinNeo / EasyMLPlatform / py / ml_models / model_task.py View on Github external
def __init__(self, taskid, mdinfo, ds, method, classfeatureindex = None):
        '''
            classfeatureindex和训练得到的模型是紧密相关的,对classfeatureindex的改动会牵涉到对模型的改动,因此classfeatureindex一定要去db_model的classfeatureindex
        '''
        clsname = mdinfo.modeltype
        if (clsname.upper() in ModelBase.AllModelInfo().keys()): 

            # dataset is load from Dataset.GetDataset
            ds['view'].classfeatureindex = mdinfo.classfeatureindex

            md = ModelBase.AllModelInfo()[clsname.upper()]['cls'](dataset = ds['view'])

            self.dataset = ds['view']
            self.model = md
            self.Load(mdinfo.model_path)

            self.assessmodel = assessment.Assessment(self.model, self.dataset)
github CalvinNeo / EasyMLPlatform / py / ml_models / model_task.py View on Github external
def __init__(self, taskid, mdinfo, ds):
        '''
            Instance and run Model according to given `model` and `dataset`

            mdinfo is a MLModel object(Database record)
            ds is {'info':dsinfo, 'view':dataset} or {'info':oldsinfo, 'view':dataset} while 
                dbds and oldsds is Dataset or OnlineDataset object
                lcdt is datasets.localdata.LocalData object
        '''
        clsname = mdinfo.modeltype
        # possibles = globals()
        # possibles.update(locals())
        if (clsname.upper() in ModelBase.AllModelInfo().keys()): # and (clsname in possibles.keys()):
            # dataset.classfeatureindex is determined by mdinfo(and when training md.classfeatureindex is determined by dataset.classfeatureindex)
            ds['view'].classfeatureindex = mdinfo.classfeatureindex

            # need to set args to __init__
            # md = possibles.get(clsname)(dataset = ds['view'])
            # print ModelBase.AllModelInfo()[clsname.upper()]
            md = ModelBase.AllModelInfo()[clsname.upper()]['cls'](dataset = ds['view'])
            md.positive = mdinfo.positive
            md.negative = mdinfo.negative
            md.classfeatureindex = mdinfo.classfeatureindex
            md.loss = {
                'QUAD': ModelBase.QuadLoss
                ,'BIN': ModelBase.BinLoss
                ,'ABS': ModelBase.AbsLoss
                ,'LOG': ModelBase.LogLoss
            }[mdinfo.loss]
github uoguelph-mlrg / Theano-MPI / lib / models / lasagne_model_zoo / vgg.py View on Github external
for layer in net.values():
            print str(lasagne.layers.get_output_shape(layer))
        
    return net
    

import numpy as np
import theano
import theano.tensor as T
rng = np.random.RandomState(23455)

import sys
sys.path.append('../lib/base/models/')
from modelbase import ModelBase 

class VGG(ModelBase): # c01b input

    '''

    overwrite those methods in the ModelBase class


    '''
    
    def __init__(self,config): 
        ModelBase.__init__(self)
        
        self.config = config
        self.verbose = config['verbose']
        
        self.name = 'vggnet'
github uoguelph-mlrg / Theano-MPI / lib / base / models / vggnet_11_shallow.py View on Github external
def __init__(self,config): 
        ModelBase.__init__(self)  

        self.config = config
        self.verbose = self.config['verbose']
        self.build_model()
github CalvinNeo / EasyMLPlatform / py / ml_models / logistic.py View on Github external
def __init__(self, dataset, classfeatureindex = -1, alpha = 0.2, maxiter = 50, *args, **kwargs):
        ModelBase.__init__(self, dataset, 'LOGISTIC', *args, **kwargs)
        self.classfeatureindex = classfeatureindex #index of the column which defines the feature in dataset
        self.Test = self.Classify2
        self.Apply = self.ClassifyDataset
        self.Train = self.Regress
        self.Save = self.DumpLogistic
        self.Load = self.LoadLogistic
        self.Graph = self.ShowImage
        self.Positive = 1
        self.Negative = -1
        # use default
        # self.T = self.RealValue
        self.tree = {}

        self.sigmoid = lambda input_n:np.vectorize(lambda n: 1.0/(1.0+math.e**(-n)))(input_n)
        self.alpha = alpha
        self.maxiter = maxiter
github uoguelph-mlrg / Theano-MPI / lib / models / vggnet_16.py View on Github external
import theano
import theano.tensor as T
import numpy as np
from layers2 import Conv,Pool,Dropout,FC,Softmax,Flatten,LRN, \
                    HeUniform, HeNormal, Constant, Normal, \
                    get_params, get_layers
from modelbase import ModelBase

# other tools minerva, chainer


class VGGNet_16(ModelBase): # c01b input
    
    def __init__(self,config): 
        ModelBase.__init__(self)  

        self.config = config
        self.verbose = self.config['verbose']
        self.build_model()
        # count params
        if self.verbose: self.count_params()
        
    def build_model(self):
        
        if self.verbose: print 'VGGNet_16 3/20'
        
        self.name = 'vggnet'
github uoguelph-mlrg / Theano-MPI / lib / models / alex_net.py View on Github external
def __init__(self, config):
        ModelBase.__init__(self)

        self.config = config
        self.verbose = self.config['verbose']
        self.name = 'alexnet'
        batch_size = config['batch_size']
        flag_datalayer = config['use_data_layer']
        lib_conv = config['lib_conv']
        n_softmax_out=config['n_softmax_out']
        # ##################### BUILD NETWORK ##########################
        # allocate symbolic variables for the data
        # 'rand' is a random array used for random cropping/mirroring of data
        x = T.ftensor4('x')
        y = T.lvector('y')
        rand = T.fvector('rand')
        lr = T.scalar('lr')

modelbase

A package to build metabolic models

MIT
Latest version published 4 days ago

Package Health Score

90 / 100
Full package analysis

Similar packages