2020-03-04 18:16:50 +00:00
|
|
|
#!/usr/bin/env python3
|
2020-03-01 18:07:02 +00:00
|
|
|
import json
|
|
|
|
from transport import factory
|
2020-03-04 17:49:18 +00:00
|
|
|
import numpy as np
|
2020-03-06 17:40:47 +00:00
|
|
|
import time
|
2020-03-01 18:07:02 +00:00
|
|
|
import os
|
2020-03-27 05:34:05 +00:00
|
|
|
from multiprocessing import Process, Lock
|
2020-03-01 18:07:02 +00:00
|
|
|
import pandas as pd
|
|
|
|
from google.oauth2 import service_account
|
2020-04-15 20:22:43 +00:00
|
|
|
from google.cloud import bigquery as bq
|
2020-03-01 18:07:02 +00:00
|
|
|
import data.maker
|
2021-03-29 16:10:57 +00:00
|
|
|
import copy
|
2020-03-01 18:07:02 +00:00
|
|
|
from data.params import SYS_ARGS
|
|
|
|
|
|
|
|
#
|
|
|
|
# The configuration array is now loaded and we will execute the pipe line as follows
|
|
|
|
|
|
|
|
class Components :
|
2020-03-27 05:34:05 +00:00
|
|
|
lock = Lock()
|
2020-03-25 22:43:23 +00:00
|
|
|
class KEYS :
|
|
|
|
PIPELINE_KEY = 'pipeline'
|
|
|
|
SQL_FILTER = 'filter'
|
2020-04-02 05:04:05 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_filter (**args):
|
|
|
|
if args['qualifier'] == 'IN' :
|
|
|
|
return ' '.join([args['field'],args['qualifier'],'(',args['value'],')'])
|
|
|
|
else:
|
|
|
|
return ' '.join([args['field'],args['qualifier'],args['value']])
|
2020-03-25 22:43:23 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_logger(**args) :
|
|
|
|
return factory.instance(type='mongo.MongoWriter',args={'dbname':'aou','doc':args['context']})
|
2020-03-04 17:49:18 +00:00
|
|
|
@staticmethod
|
|
|
|
def get(args):
|
|
|
|
"""
|
|
|
|
This function returns a data-frame provided a bigquery sql statement with conditions (and limits for testing purposes)
|
|
|
|
The function must be wrapped around a lambda this makes testing easier and changing data stores transparent to the rest of the code. (Vital when testing)
|
|
|
|
:sql basic sql statement
|
|
|
|
:condition optional condition and filters
|
|
|
|
"""
|
|
|
|
SQL = args['sql']
|
2020-03-25 22:43:23 +00:00
|
|
|
if Components.KEYS.SQL_FILTER in args :
|
2020-04-02 05:04:05 +00:00
|
|
|
FILTER_KEY = Components.KEYS.SQL_FILTER
|
|
|
|
SQL_FILTER = args[FILTER_KEY] if type(args[FILTER_KEY]) == list else [args[FILTER_KEY]]
|
|
|
|
# condition = ' '.join([args[FILTER_KEY]['field'],args[FILTER_KEY]['qualifier'],'(',args[FILTER_KEY]['value'],')'])
|
|
|
|
|
|
|
|
condition = ' AND '.join([Components.get_filter(**item) for item in SQL_FILTER])
|
2020-03-04 17:49:18 +00:00
|
|
|
SQL = " ".join([SQL,'WHERE',condition])
|
2020-03-01 18:07:02 +00:00
|
|
|
|
2020-03-08 13:48:38 +00:00
|
|
|
SQL = SQL.replace(':dataset',args['dataset']) #+ " LI "
|
|
|
|
|
2020-03-04 17:49:18 +00:00
|
|
|
if 'limit' in args :
|
2020-03-08 13:48:38 +00:00
|
|
|
SQL = SQL + ' LIMIT ' + args['limit']
|
2020-03-25 22:43:23 +00:00
|
|
|
#
|
|
|
|
# let's log the sql query that has been performed here
|
|
|
|
logger = factory.instance(type='mongo.MongoWriter',args={'dbname':'aou','doc':args['context']})
|
|
|
|
logger.write({"module":"bigquery","action":"read","input":{"sql":SQL}})
|
2020-03-04 17:49:18 +00:00
|
|
|
credentials = service_account.Credentials.from_service_account_file('/home/steve/dev/aou/accounts/curation-prod.json')
|
2020-04-01 05:21:51 +00:00
|
|
|
df = pd.read_gbq(SQL,credentials=credentials,dialect='standard')
|
2020-03-04 17:49:18 +00:00
|
|
|
return df
|
|
|
|
|
|
|
|
# return lambda: pd.read_gbq(SQL,credentials=credentials,dialect='standard')[args['columns']].dropna()
|
|
|
|
@staticmethod
|
|
|
|
def split(X,MAX_ROWS=3,PART_SIZE=3):
|
|
|
|
|
|
|
|
return list(pd.cut( np.arange(X.shape[0]+1),PART_SIZE).categories)
|
2020-03-01 18:07:02 +00:00
|
|
|
|
2020-03-04 17:49:18 +00:00
|
|
|
def train(self,**args):
|
|
|
|
"""
|
|
|
|
This function will perform training on the basis of a given pointer that reads data
|
2020-03-01 18:07:02 +00:00
|
|
|
|
2020-03-04 17:49:18 +00:00
|
|
|
"""
|
2021-03-29 16:10:57 +00:00
|
|
|
schema = None
|
|
|
|
if 'file' in args :
|
|
|
|
|
|
|
|
df = pd.read_csv(args['file'])
|
|
|
|
del args['file']
|
|
|
|
elif 'data' not in args :
|
|
|
|
reader = factory.instance(**args['store']['source'])
|
|
|
|
if 'row_limit' in args :
|
|
|
|
df = reader.read(sql=args['sql'],limit=args['row_limit'])
|
|
|
|
else:
|
|
|
|
df = reader.read(sql=args['sql'])
|
|
|
|
schema = reader.meta(table=args['from']) if hasattr(reader,'meta') and 'from' in args else None
|
2020-03-04 17:49:18 +00:00
|
|
|
else:
|
2021-03-29 16:10:57 +00:00
|
|
|
df = args['data']
|
|
|
|
|
|
|
|
|
|
|
|
# df = df.fillna('')
|
|
|
|
if schema :
|
|
|
|
_schema = {}
|
|
|
|
for _item in schema :
|
|
|
|
_type = int
|
|
|
|
_value = 0
|
|
|
|
if _item.field_type == 'FLOAT' :
|
|
|
|
_type =float
|
|
|
|
elif _item.field_type != 'INTEGER' :
|
|
|
|
_type = str
|
|
|
|
_value = ''
|
|
|
|
_schema[_item.name] = _type
|
|
|
|
df[_item.name] = df[_item.name].fillna(_value).astype(_type)
|
|
|
|
args['schema'] = _schema
|
|
|
|
# df[_item.name] = df[_item.name].astype(_type)
|
|
|
|
_args = copy.deepcopy(args)
|
|
|
|
# _args['store'] = args['store']['source']
|
|
|
|
_args['data'] = df
|
2020-03-08 13:48:38 +00:00
|
|
|
|
|
|
|
data.maker.train(**_args)
|
2020-04-12 09:50:54 +00:00
|
|
|
|
2020-04-13 01:07:15 +00:00
|
|
|
if 'autopilot' in ( list(args.keys())) :
|
2021-03-29 16:10:57 +00:00
|
|
|
print (['autopilot mode enabled ....',args['context']])
|
2020-04-13 01:07:15 +00:00
|
|
|
self.generate(args)
|
2020-03-04 17:49:18 +00:00
|
|
|
|
|
|
|
pass
|
2020-04-29 06:27:25 +00:00
|
|
|
|
2020-04-15 20:22:43 +00:00
|
|
|
def post(self,args):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2020-03-04 17:49:18 +00:00
|
|
|
# @staticmethod
|
|
|
|
def generate(self,args):
|
|
|
|
"""
|
|
|
|
This function will generate data and store it to a given,
|
|
|
|
"""
|
2021-03-29 16:10:57 +00:00
|
|
|
store = args['store']['logs']
|
|
|
|
store['doc'] = args['context']
|
|
|
|
logger = factory.instance(**store) #type='mongo.MongoWriter',args={'dbname':'aou','doc':args['context']})
|
|
|
|
|
|
|
|
ostore = args['store']['target']
|
|
|
|
writer = factory.instance(**ostore)
|
|
|
|
# log_folder = args['logs'] if 'logs' in args else 'logs'
|
|
|
|
# partition = args['partition'] if 'partition' in args else ''
|
|
|
|
# log_folder = os.sep.join([log_folder,args['context'],str(partition)])
|
|
|
|
|
|
|
|
# _args = {"batch_size":2000,"logs":log_folder,"context":args['context'],"max_epochs":150,"column":args['columns'],"id":"person_id","logger":logger}
|
|
|
|
# _args['max_epochs'] = 150 if 'max_epochs' not in args else int(args['max_epochs'])
|
2020-03-06 20:20:06 +00:00
|
|
|
# _args['num_gpu'] = int(args['num_gpu']) if 'num_gpu' in args else 1
|
2021-03-29 16:10:57 +00:00
|
|
|
# if 'batch_size' in args :
|
|
|
|
# _args['batch_size'] = int(args['batch_size'])
|
|
|
|
|
|
|
|
# if int(args['num_gpu']) > 1 :
|
|
|
|
# _args['gpu'] = int(args['gpu']) if int(args['gpu']) < 8 else np.random.choice(np.arange(8)).astype(int)
|
|
|
|
# else:
|
|
|
|
# _args['gpu'] = 0
|
|
|
|
# _args['num_gpu'] = 1
|
|
|
|
# os.environ['CUDA_VISIBLE_DEVICES'] = str(args['gpu'])
|
|
|
|
# # _args['no_value']= args['no_value']
|
|
|
|
# _args['matrix_size'] = args['matrix_size'] if 'matrix_size' in args else 128
|
2020-04-14 21:24:02 +00:00
|
|
|
|
2020-03-25 22:43:23 +00:00
|
|
|
|
2021-03-29 16:10:57 +00:00
|
|
|
# # MAX_ROWS = args['max_rows'] if 'max_rows' in args else 0
|
|
|
|
# PART_SIZE = int(args['part_size']) if 'part_size' in args else 8
|
2020-03-04 17:49:18 +00:00
|
|
|
|
|
|
|
# credentials = service_account.Credentials.from_service_account_file('/home/steve/dev/aou/accounts/curation-prod.json')
|
|
|
|
# _args['data'] = pd.read_gbq(SQL,credentials=credentials,dialect='standard').dropna()
|
2020-03-06 20:20:06 +00:00
|
|
|
# reader = args['reader']
|
|
|
|
# df = reader()
|
2021-03-29 16:10:57 +00:00
|
|
|
schema = args['schema'] if 'schema' in args else None
|
|
|
|
if 'file' in args :
|
2020-04-14 12:26:24 +00:00
|
|
|
|
2021-03-29 16:10:57 +00:00
|
|
|
df = pd.read_csv(args['file'])
|
|
|
|
else:
|
|
|
|
if 'data' not in args :
|
|
|
|
reader = factory.instance(**args['store']['source'])
|
|
|
|
if 'row_limit' in args :
|
|
|
|
df = reader.read(sql=args['sql'],limit=args['row_limit'])
|
|
|
|
else:
|
|
|
|
df = reader.read(sql=args['sql'])
|
|
|
|
if 'schema' not in args and hasattr(reader,'meta'):
|
|
|
|
schema = reader.meta(table=args['from'])
|
2020-04-12 09:50:54 +00:00
|
|
|
|
2021-03-29 16:10:57 +00:00
|
|
|
|
|
|
|
else:
|
|
|
|
#
|
|
|
|
# This will account for autopilot mode ...
|
|
|
|
df = args['data']
|
|
|
|
|
|
|
|
_info = {"module":"gan-prep","action":"read","shape":{"rows":df.shape[0],"columns":df.shape[0]}}
|
2020-04-02 12:52:09 +00:00
|
|
|
|
2021-03-29 16:10:57 +00:00
|
|
|
|
2020-04-02 05:04:05 +00:00
|
|
|
_dc = pd.DataFrame()
|
|
|
|
# for mdf in df :
|
2021-03-29 16:10:57 +00:00
|
|
|
args['data'] = df
|
|
|
|
args['candidates'] = 1 if 'candidates' not in args else int(args['candidates'])
|
|
|
|
|
|
|
|
candidates = (data.maker.generate(**args))
|
|
|
|
if 'sql.BQWriter' in ostore['type'] :
|
|
|
|
#table = ".".join([ostore['['dataset'],args['context']])
|
|
|
|
# writer = factory.instance(**ostore)
|
|
|
|
_columns = None
|
|
|
|
skip_columns = []
|
|
|
|
_schema = [{"name":field.name,"type":field.field_type,"description":field.description} for field in schema] if schema else []
|
|
|
|
for _df in candidates :
|
|
|
|
#
|
|
|
|
# we need to format the fields here to make sure we have something cohesive
|
|
|
|
#
|
|
|
|
|
|
|
|
if not skip_columns :
|
|
|
|
# _columns = set(df.columns) - set(_df.columns)
|
|
|
|
if 'ignore' in args and 'columns' in args['ignore'] :
|
|
|
|
|
|
|
|
for name in args['ignore']['columns'] :
|
|
|
|
for _name in _df.columns:
|
|
|
|
if _name in name:
|
|
|
|
skip_columns.append(_name)
|
|
|
|
#
|
|
|
|
# We perform a series of set operations to insure that the following conditions are met:
|
|
|
|
# - the synthetic dataset only has fields that need to be synthesized
|
|
|
|
# - The original dataset has all the fields except those that need to be synthesized
|
|
|
|
#
|
|
|
|
|
|
|
|
_df = _df[list(set(_df.columns) - set(skip_columns))]
|
|
|
|
|
|
|
|
if set(df.columns) & set(_df.columns) :
|
|
|
|
_columns = set(df.columns) - set(_df.columns)
|
|
|
|
df = df[_columns]
|
|
|
|
|
|
|
|
#
|
|
|
|
# Let us merge the dataset here and and have a comprehensive dataset
|
|
|
|
|
|
|
|
_df = pd.DataFrame.join(df,_df)
|
|
|
|
|
|
|
|
writer.write(_df,schema=_schema,table=args['from'])
|
|
|
|
# writer.write(df,table=table)
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
pass
|
|
|
|
|
2020-04-14 05:18:23 +00:00
|
|
|
|
2021-03-29 16:10:57 +00:00
|
|
|
# #
|
|
|
|
# # We need to post the generate the data in order to :
|
|
|
|
# # 1. compare immediately
|
|
|
|
# # 2. synthetic copy
|
|
|
|
# #
|
2020-03-04 17:49:18 +00:00
|
|
|
|
2021-03-29 16:10:57 +00:00
|
|
|
# cols = _dc.columns.tolist()
|
2020-03-04 17:49:18 +00:00
|
|
|
|
2021-03-29 16:10:57 +00:00
|
|
|
# data_comp = _args['data'][args['columns']].join(_dc[args['columns']],rsuffix='_io') #-- will be used for comparison (store this in big query)
|
|
|
|
# #
|
|
|
|
# # performing basic analytics on the synthetic data generated (easy to quickly asses)
|
|
|
|
# #
|
|
|
|
# info = {"module":"generate","action":"io.metrics","input":{"rows":data_comp.shape[0],"partition":partition,"logs":[]}}
|
2020-04-15 20:51:53 +00:00
|
|
|
|
2021-03-29 16:10:57 +00:00
|
|
|
# #
|
|
|
|
# # @TODO: Send data over to a process for analytics
|
2020-03-19 04:16:36 +00:00
|
|
|
|
2021-03-29 16:10:57 +00:00
|
|
|
# base_cols = list(set(_args['data'].columns) - set(args['columns'])) #-- rebuilt the dataset (and store it)
|
|
|
|
# cols = _dc.columns.tolist()
|
|
|
|
# for name in cols :
|
|
|
|
# _args['data'][name] = _dc[name]
|
2020-03-04 17:49:18 +00:00
|
|
|
|
2021-03-29 16:10:57 +00:00
|
|
|
# #
|
|
|
|
# #-- Let us store all of this into bigquery
|
|
|
|
# prefix = args['notify']+'.'+_args['context']
|
|
|
|
# partition = str(partition)
|
|
|
|
# table = '_'.join([prefix,partition,'io']).replace('__','_')
|
|
|
|
# folder = os.sep.join([args['logs'],args['context'],partition,'output'])
|
|
|
|
# if 'file' in args :
|
2020-03-04 17:49:18 +00:00
|
|
|
|
2021-03-29 16:10:57 +00:00
|
|
|
# _fname = os.sep.join([folder,table.replace('_io','_full_io.csv')])
|
|
|
|
# _pname = os.sep.join([folder,table])+'.csv'
|
|
|
|
# data_comp.to_csv( _pname,index=False)
|
|
|
|
# _args['data'].to_csv(_fname,index=False)
|
2020-03-04 17:49:18 +00:00
|
|
|
|
2021-03-29 16:10:57 +00:00
|
|
|
# _id = 'path'
|
|
|
|
# else:
|
2020-04-15 20:22:43 +00:00
|
|
|
|
2021-03-29 16:10:57 +00:00
|
|
|
# credentials = service_account.Credentials.from_service_account_file('/home/steve/dev/aou/accounts/curation-prod.json')
|
|
|
|
# _pname = os.sep.join([folder,table+'.csv'])
|
|
|
|
# _fname = table.replace('_io','_full_io')
|
|
|
|
# partial = '.'.join(['io',args['context']+'_partial_io'])
|
|
|
|
# complete= '.'.join(['io',args['context']+'_full_io'])
|
|
|
|
# data_comp.to_csv(_pname,index=False)
|
|
|
|
# if 'dump' in args :
|
|
|
|
# print (_args['data'].head())
|
|
|
|
# else:
|
|
|
|
# Components.lock.acquire()
|
|
|
|
# data_comp.to_gbq(if_exists='append',destination_table=partial,credentials=credentials,chunksize=90000)
|
|
|
|
# _args['data'].to_gbq(if_exists='append',destination_table=complete,credentials=credentials,chunksize=90000)
|
|
|
|
# Components.lock.release()
|
|
|
|
# _id = 'dataset'
|
|
|
|
# info = {"full":{_id:_fname,"rows":_args['data'].shape[0]},"partial":{"path":_pname,"rows":data_comp.shape[0]} }
|
|
|
|
# if partition :
|
|
|
|
# info ['partition'] = int(partition)
|
|
|
|
# logger.write({"module":"generate","action":"write","input":info} )
|
2020-03-06 17:40:47 +00:00
|
|
|
|
2020-03-25 22:43:23 +00:00
|
|
|
|
2020-03-04 17:49:18 +00:00
|
|
|
|
2020-03-01 18:07:02 +00:00
|
|
|
if __name__ == '__main__' :
|
2020-03-04 17:49:18 +00:00
|
|
|
filename = SYS_ARGS['config'] if 'config' in SYS_ARGS else 'config.json'
|
|
|
|
f = open (filename)
|
2020-03-25 22:43:23 +00:00
|
|
|
_config = json.loads(f.read())
|
2020-03-04 17:49:18 +00:00
|
|
|
f.close()
|
2020-03-25 22:43:23 +00:00
|
|
|
PIPELINE = _config['pipeline']
|
2020-03-16 21:22:34 +00:00
|
|
|
index = SYS_ARGS['index']
|
|
|
|
if index.isnumeric() :
|
|
|
|
index = int(SYS_ARGS['index'])
|
|
|
|
else:
|
|
|
|
#
|
|
|
|
# The index provided is a key to a pipeline entry mainly the context
|
|
|
|
#
|
|
|
|
N = len(PIPELINE)
|
|
|
|
f = [i for i in range(0,N) if PIPELINE[i]['context'] == index]
|
|
|
|
index = f[0] if f else 0
|
|
|
|
#
|
2020-04-02 05:04:05 +00:00
|
|
|
|
2020-03-16 21:22:34 +00:00
|
|
|
print ("..::: ",PIPELINE[index]['context'])
|
2020-03-04 17:49:18 +00:00
|
|
|
args = (PIPELINE[index])
|
2020-03-25 22:43:23 +00:00
|
|
|
for key in _config :
|
|
|
|
if key == 'pipeline' or key in args:
|
|
|
|
#
|
|
|
|
# skip in case of pipeline or if key exists in the selected pipeline (provided by index)
|
|
|
|
#
|
|
|
|
continue
|
|
|
|
args[key] = _config[key]
|
2020-04-02 05:04:05 +00:00
|
|
|
|
2020-03-04 17:49:18 +00:00
|
|
|
args = dict(args,**SYS_ARGS)
|
2020-04-14 21:24:02 +00:00
|
|
|
if 'matrix_size' in args :
|
|
|
|
args['matrix_size'] = int(args['matrix_size'])
|
2020-04-01 05:53:56 +00:00
|
|
|
if 'batch_size' not in args :
|
|
|
|
args['batch_size'] = 2000 #if 'batch_size' not in args else int(args['batch_size'])
|
2020-03-04 20:30:40 +00:00
|
|
|
if 'dataset' not in args :
|
|
|
|
args['dataset'] = 'combined20191004v2_deid'
|
2020-03-08 13:48:38 +00:00
|
|
|
PART_SIZE = int(args['part_size']) if 'part_size' in args else 8
|
2020-03-04 17:49:18 +00:00
|
|
|
#
|
|
|
|
# @TODO:
|
|
|
|
# Log what was initiated so we have context of this processing ...
|
|
|
|
#
|
2020-04-02 05:04:05 +00:00
|
|
|
# if 'listen' not in SYS_ARGS :
|
2021-03-29 16:10:57 +00:00
|
|
|
# if 'file' in args :
|
|
|
|
# DATA = pd.read_csv(args['file']) ;
|
|
|
|
# schema = []
|
|
|
|
# else:
|
|
|
|
# DATA = Components().get(args)
|
|
|
|
# client = bq.Client.from_service_account_json(args["private_key"])
|
|
|
|
# schema = client.get_table(client.dataset(args['dataset']).table(args['from'])).schema
|
2020-04-15 20:51:53 +00:00
|
|
|
|
2021-03-29 16:10:57 +00:00
|
|
|
# COLUMNS = DATA.columns
|
|
|
|
# DATA = np.array_split(DATA,PART_SIZE)
|
|
|
|
# args['schema'] = schema
|
2020-03-04 17:49:18 +00:00
|
|
|
if 'generate' in SYS_ARGS :
|
|
|
|
#
|
|
|
|
# Let us see if we have partitions given the log folder
|
|
|
|
|
2021-03-29 16:10:57 +00:00
|
|
|
content = os.listdir( os.sep.join([args['logs'],'train',args['context']]))
|
2020-03-04 17:49:18 +00:00
|
|
|
generator = Components()
|
2020-03-08 13:48:38 +00:00
|
|
|
|
2021-03-29 16:10:57 +00:00
|
|
|
# if ''.join(content).isnumeric() :
|
|
|
|
# #
|
|
|
|
# # we have partitions we are working with
|
2020-03-07 15:16:17 +00:00
|
|
|
|
2021-03-29 16:10:57 +00:00
|
|
|
# jobs = []
|
2020-03-08 13:48:38 +00:00
|
|
|
|
2021-03-29 16:10:57 +00:00
|
|
|
# # columns = DATA.columns.tolist()
|
2020-03-08 13:48:38 +00:00
|
|
|
|
2021-03-29 16:10:57 +00:00
|
|
|
# # DATA = np.array_split(DATA,PART_SIZE)
|
2020-03-06 20:56:28 +00:00
|
|
|
|
2021-03-29 16:10:57 +00:00
|
|
|
# for index in range(0,PART_SIZE) :
|
|
|
|
# if 'focus' in args and int(args['focus']) != index :
|
|
|
|
# #
|
|
|
|
# # This handles failures/recoveries for whatever reason
|
|
|
|
# # If we are only interested in generating data for a given partition
|
|
|
|
# continue
|
|
|
|
# # index = id.index(id)
|
2020-03-08 13:48:38 +00:00
|
|
|
|
2021-03-29 16:10:57 +00:00
|
|
|
# args['partition'] = index
|
|
|
|
# args['data'] = DATA[index]
|
|
|
|
# if int(args['num_gpu']) > 1 :
|
|
|
|
# args['gpu'] = index
|
|
|
|
# else:
|
|
|
|
# args['gpu']=0
|
2020-04-02 05:04:05 +00:00
|
|
|
|
2021-03-29 16:10:57 +00:00
|
|
|
# make = lambda _args: (Components()).generate(_args)
|
|
|
|
# job = Process(target=make,args=(args,))
|
|
|
|
# job.name = 'generator # '+str(index)
|
|
|
|
# job.start()
|
|
|
|
# jobs.append(job)
|
|
|
|
# # if len(jobs) == 1 :
|
|
|
|
# # job.join()
|
2020-03-06 19:00:32 +00:00
|
|
|
|
2021-03-29 16:10:57 +00:00
|
|
|
# print (["Started ",len(jobs),"generators" if len(jobs)>1 else "generator" ])
|
|
|
|
# while len(jobs)> 0 :
|
|
|
|
# jobs = [job for job in jobs if job.is_alive()]
|
|
|
|
# time.sleep(2)
|
2020-03-04 17:49:18 +00:00
|
|
|
|
2021-03-29 16:10:57 +00:00
|
|
|
# # generator.generate(args)
|
|
|
|
# else:
|
|
|
|
# generator.generate(args)
|
2020-03-04 17:49:18 +00:00
|
|
|
# Components.generate(args)
|
2021-03-29 16:10:57 +00:00
|
|
|
generator.generate(args)
|
|
|
|
|
2020-03-04 17:49:18 +00:00
|
|
|
else:
|
2020-03-08 13:48:38 +00:00
|
|
|
|
|
|
|
# DATA = np.array_split(DATA,PART_SIZE)
|
2021-03-29 16:10:57 +00:00
|
|
|
agent = Components()
|
|
|
|
agent.train(**args)
|
|
|
|
# jobs = []
|
|
|
|
# for index in range(0,PART_SIZE) :
|
|
|
|
# if 'focus' in args and int(args['focus']) != index :
|
|
|
|
# continue
|
|
|
|
# args['part_size'] = PART_SIZE
|
|
|
|
# args['partition'] = index
|
|
|
|
# args['data'] = DATA[index]
|
|
|
|
# if int(args['num_gpu']) > 1 :
|
|
|
|
# args['gpu'] = index
|
|
|
|
# else:
|
|
|
|
# args['gpu']=0
|
2020-03-08 13:48:38 +00:00
|
|
|
|
2021-03-29 16:10:57 +00:00
|
|
|
# make = lambda _args: (Components()).train(**_args)
|
|
|
|
# job = Process(target=make,args=( dict(args),))
|
|
|
|
# job.name = 'Trainer # ' + str(index)
|
|
|
|
# job.start()
|
|
|
|
# jobs.append(job)
|
|
|
|
# # args['gpu']
|
|
|
|
# print (["Started ",len(jobs),"trainers" if len(jobs)>1 else "trainer" ])
|
|
|
|
# while len(jobs)> 0 :
|
|
|
|
# jobs = [job for job in jobs if job.is_alive()]
|
|
|
|
# time.sleep(2)
|
2020-03-07 15:16:17 +00:00
|
|
|
|
|
|
|
# trainer = Components()
|
|
|
|
# trainer.train(**args)
|
|
|
|
|
2020-03-04 17:49:18 +00:00
|
|
|
|
|
|
|
# Components.train(**args)
|
2020-03-01 18:07:02 +00:00
|
|
|
#for args in PIPELINE :
|
2020-03-04 17:49:18 +00:00
|
|
|
#args['dataset'] = 'combined20190510'
|
|
|
|
#process = Process(target=Components.train,args=(args,))
|
|
|
|
#process.name = args['context']
|
|
|
|
#process.start()
|
|
|
|
# Components.train(args)
|