def __init__(self, name=None, passwd=None, project=None, flag='non-sys', domain='default'): self.__users_url = ('http://' + utils.init_data().get('host', 'IP') + ':' + utils.init_data().get('keystone', 'PORT') + '/' + utils.init_data().get('keystone', 'VERSION') + '/users') self.flag = flag self.domain = domain self.name = name self.passwd = passwd self.project = project self.identification = None self.enable = False self.endpoint = {} # TODO(dc) user quota # TODO(dc) self.quota = None self.token = utils.get_token(self) self.headers = { 'User-Agent': utils.init_data().get('agent', 'ALL'), 'X-Auth-Token': self.token, "Content-type": "application/json", "Accept": "application/json" } self._set_info()
def load_data(args): """ Iterate through each file in data_folder and construct the input data features (40-len DNA). :param data_folder: path to folder of data :param exclude: kth file to exclude in cross-validation :returns type list: list of dicts for DNA-arr & label """ data = init_data(args) x = data['X_plus'] + data['X_minus'] y = data['Y_plus'] + data['Y_minus'] ret = [] for img, label in zip(x, y): ret.append({'x': img, 'y': label}) # for f_path in glob.glob(data_files): # with open(f_path) as f_in: # for line in f_in.read().splitlines(): # dna_arr, label = convert_data(line) # data.append({ # 'x': dna_arr, # 'y': label # }) return ret
def start_train(epochs=10000, target_park='宝琳珠宝交易中心', start='2016-01-02', end='2017-01-02'): seqs_normal, adj, node_f, nks, conns, _, _ = utils.init_data( target_park, start, end) batch_size = 96 * 7 * fix_weeks seqs_normal = seqs_normal.take(range(96 * 7 * 0, 96 * 7 * total_weeks)) use_gru_bag = [True, False] use_gcn_bag = [True, False] monitor = False for (use_gru, use_gcn) in itertools.product(use_gru_bag, use_gcn_bag): name = target_park + '/GAN' + ('_GCN' if use_gcn else '') + ('_GRU' if use_gru else '') print('Starting ' + name) site_path = root_path + name if not os.path.exists(site_path): os.makedirs(site_path) else: continue describe_site(nks, seqs_normal, site_path, target_park, node_f) train = Train(seqs_normal, adj, node_f, epochs, nks[target_park], use_gcn, batch_size, use_gru) # print(train.generator.summary()) train_time_consumed, final_epoch = train(epochs, site_path, batch_size, monitor) if final_epoch < epochs: epochs = final_epoch monitor = False # evaluation metrics_ = train.evaluate(site_path, batch_size) metrics_['name'] = name metrics_['train_time_consumed'] = round(train_time_consumed, 2) metrics_['final_epoch'] = final_epoch metrics.write_metrics(root_path, metrics_)
def main(FLAGS): train_data, test_data = init_data(FLAGS) assert FLAGS.model_type in ['conv', 'res'] if FLAGS.model_type == 'conv': model = ConvModel(train_data, test_data, FLAGS) elif FLAGS.model_type == 'res': model = ResModel(train_data, test_data, FLAGS) model.compile() model.train()
def __init__(self): self.token = utils.get_token() self.enable = True self.__headers = { 'User-Agent': utils.init_data().get('agent', 'ALL'), 'X-Auth-Token': self.token, "Content-type": "application/json", "Accept": "application/json" } self.__roles_url = utils.get_endpoint(self.token, 'keystone') + '/roles'
def register_user( key=None, auth='vdc' ): # TODO(dc): domain is not concerned and set to default """ :param key: openstack project key that database contain :param auth: access openstack model and value is 'system' and 'vdc' :return: class user that will be used in other api """ project_manager = project.ProjectManger() user_manager = user.UserManager() if auth == 'system' and key is None: return user_manager.get( name=utils.init_data().get('host', 'ADMIN'), passwd=utils.init_data().get('host', 'PASSWD'), project=project_manager.get( name=utils.init_data().get('host', 'PROJECT')), domain=utils.init_data().get('host', 'DOMAIN'), flag='sys') elif auth == 'vdc': if key is None: warnings.warn("Wrong param key!") return None if isinstance(key, str) is False: warnings.warn("Wrong param key!") return None return user_manager.get( project=project_manager.get(key[0:(len(key) / 3)]), name=key[(len(key) / 3):(2 * len(key) / 3)], passwd=key[(2 * len(key) / 3):], domain=utils.init_data().get('host', 'DOMAIN')) else: warnings.warn("Register_user wrong auth parameters!")
import warnings import cv2 as cv import tensorflow as tf import utils from matplotlib import pyplot as plt PLOT_PNG = '_plot.png' COLOR_TITLE = 'maroon' FONT_SIZE = 20 FIG_SIZE = 7 warnings.simplefilter(action='ignore', category=FutureWarning) path = 'static/animals' path_gen = 'static/generated/' categories, img_size, norm = utils.init_data(path) seq_model = tf.keras.models.load_model('static/models/model-20.model', compile=False) def show_category_probability(predictions, animal_predicted): colors = ['magenta', 'turquoise', 'yellow'] # Cat, Dog, Panda respectively explode = (0.03, 0.03, 0.03) percentage = [predictions[0][0], predictions[0][1], predictions[0][2]] plt.figure(figsize=[FIG_SIZE, FIG_SIZE]) plt.title('Animal Probability', fontsize=FONT_SIZE, color=COLOR_TITLE) plt.pie(percentage, labels=categories, autopct='%1.4f%%', explode=explode,