本文整理匯總了Python中util.get_config方法的典型用法代碼示例。如果您正苦於以下問題:Python util.get_config方法的具體用法?Python util.get_config怎麽用?Python util.get_config使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類util
的用法示例。
在下文中一共展示了util.get_config方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: restore_best_model
# 需要導入模塊: import util [as 別名]
# 或者: from util import get_config [as 別名]
def restore_best_model(self):
"""Load bestmodel file from eval directory, add variables for adagrad, and save to train directory"""
tf.logging.info("Restoring bestmodel for training...")
# Initialize all vars in the model
sess = tf.Session(config=util.get_config())
print("Initializing all variables...")
sess.run(tf.initialize_all_variables())
# Restore the best model from eval dir
saver = tf.train.Saver([v for v in tf.all_variables() if "Adagrad" not in v.name])
print("Restoring all non-adagrad variables from best model in eval dir...")
curr_ckpt = util.load_ckpt(saver, sess, "eval")
print("Restored %s." % curr_ckpt)
# Save this model to train dir and quit
new_model_name = curr_ckpt.split("/")[-1].replace("bestmodel", "model")
new_fname = os.path.join(FLAGS.log_root, "train", new_model_name)
print("Saving model to %s..." % (new_fname))
new_saver = tf.train.Saver() # this saver saves all variables that now exist, including Adagrad variables
new_saver.save(sess, new_fname)
print("Saved.")
exit()
示例2: convert_to_coverage_model
# 需要導入模塊: import util [as 別名]
# 或者: from util import get_config [as 別名]
def convert_to_coverage_model(self):
"""Load non-coverage checkpoint, add initialized extra variables for coverage, and save as new checkpoint"""
tf.logging.info("converting non-coverage model to coverage model..")
# initialize an entire coverage model from scratch
sess = tf.Session(config=util.get_config())
print("initializing everything...")
sess.run(tf.global_variables_initializer())
# load all non-coverage weights from checkpoint
saver = tf.train.Saver([v for v in tf.global_variables() if "coverage" not in v.name and "Adagrad" not in v.name])
print("restoring non-coverage variables...")
curr_ckpt = util.load_ckpt(saver, sess)
print("restored.")
# save this model and quit
new_fname = curr_ckpt + '_cov_init'
print("saving model to %s..." % (new_fname))
new_saver = tf.train.Saver() # this one will save all variables that now exist
new_saver.save(sess, new_fname)
print("saved.")
exit()
示例3: convert_to_reinforce_model
# 需要導入模塊: import util [as 別名]
# 或者: from util import get_config [as 別名]
def convert_to_reinforce_model(self):
"""Load non-reinforce checkpoint, add initialized extra variables for reinforce, and save as new checkpoint"""
tf.logging.info("converting non-reinforce model to reinforce model..")
# initialize an entire reinforce model from scratch
sess = tf.Session(config=util.get_config())
print("initializing everything...")
sess.run(tf.global_variables_initializer())
# load all non-reinforce weights from checkpoint
saver = tf.train.Saver([v for v in tf.global_variables() if "reinforce" not in v.name and "Adagrad" not in v.name])
print("restoring non-reinforce variables...")
curr_ckpt = util.load_ckpt(saver, sess)
print("restored.")
# save this model and quit
new_fname = curr_ckpt + '_rl_init'
print("saving model to %s..." % (new_fname))
new_saver = tf.train.Saver() # this one will save all variables that now exist
new_saver.save(sess, new_fname)
print("saved.")
exit()
示例4: restore_best_model
# 需要導入模塊: import util [as 別名]
# 或者: from util import get_config [as 別名]
def restore_best_model():
"""Load bestmodel file from eval directory, add variables for adagrad, and save to train directory"""
tf.logging.info("Restoring best model for training...")
# Initialize all vars in the model
sess = tf.Session(config=util.get_config())
print("Initializing all variables...")
sess.run(tf.initialize_all_variables())
# Restore the best model from eval dir
saver = tf.train.Saver([v for v in tf.all_variables() if "Adagrad" not in v.name])
print("Restoring all non-adagrad variables from best model in eval dir...")
curr_ckpt = util.load_ckpt(saver, sess, "eval")
print("Restored %s." % curr_ckpt)
# Save this model to train dir and quit
new_model_name = curr_ckpt.split("/")[-1].replace("bestmodel", "model")
new_fname = os.path.join(FLAGS.log_root, "train", new_model_name)
print("Saving model to %s..." % new_fname)
new_saver = tf.train.Saver() # this saver saves all variables that now exist, including Adagrad variables
new_saver.save(sess, new_fname)
print("Saved.")
exit()
示例5: convert_to_coverage_model
# 需要導入模塊: import util [as 別名]
# 或者: from util import get_config [as 別名]
def convert_to_coverage_model():
"""Load non-coverage checkpoint, add initialized extra variables for coverage, and save as new checkpoint"""
tf.logging.info("converting non-coverage model to coverage model..")
# initialize an entire coverage model from scratch
sess = tf.Session(config=util.get_config())
print("initializing everything...")
sess.run(tf.global_variables_initializer())
# load all non-coverage weights from checkpoint
saver = tf.train.Saver([v for v in tf.global_variables() if "coverage" not in v.name and "Adagrad" not in v.name])
print("restoring non-coverage variables...")
curr_ckpt = util.load_ckpt(saver, sess, FLAGS.ckpt_dir)
print("restored.")
# save this model and quit
new_fname = curr_ckpt + '_cov_init'
print("saving model to %s..." % new_fname)
new_saver = tf.train.Saver() # this one will save all variables that now exist
new_saver.save(sess, new_fname)
print("saved.")
exit()
示例6: convert_to_coverage_model
# 需要導入模塊: import util [as 別名]
# 或者: from util import get_config [as 別名]
def convert_to_coverage_model():
"""Load non-coverage checkpoint, add initialized extra variables for coverage, and save as new checkpoint"""
tf.logging.info("converting non-coverage model to coverage model..")
# initialize an entire coverage model from scratch
sess = tf.Session(config=util.get_config())
print("initializing everything...")
sess.run(tf.global_variables_initializer())
# load all non-coverage weights from checkpoint
saver = tf.train.Saver([v for v in tf.global_variables(
) if "coverage" not in v.name and "Adagrad" not in v.name])
print("restoring non-coverage variables...")
curr_ckpt = util.load_ckpt(saver, sess)
print("restored.")
# save this model and quit
new_fname = curr_ckpt + '_cov_init'
print("saving model to %s..." % (new_fname))
new_saver = tf.train.Saver() # this one will save all variables that now exist
new_saver.save(sess, new_fname)
print("saved.")
exit()
示例7: restore_best_model
# 需要導入模塊: import util [as 別名]
# 或者: from util import get_config [as 別名]
def restore_best_model():
"""Load bestmodel file from eval directory, add variables for adagrad, and save to train directory"""
tf.logging.info("Restoring bestmodel for training...")
# Initialize all vars in the model
sess = tf.Session(config=util.get_config())
print("Initializing all variables...")
sess.run(tf.initialize_all_variables())
# Restore the best model from eval dir
saver = tf.train.Saver([v for v in tf.all_variables() if "Adagrad" not in v.name])
print("Restoring all non-adagrad variables from best model in eval dir...")
curr_ckpt = util.load_ckpt(saver, sess, "eval")
print("Restored %s." % curr_ckpt)
# Save this model to train dir and quit
new_model_name = curr_ckpt.split("/")[-1].replace("bestmodel", "model")
new_fname = os.path.join(FLAGS.log_root, "train", new_model_name)
print("Saving model to %s..." % (new_fname))
new_saver = tf.train.Saver() # this saver saves all variables that now exist, including Adagrad variables
new_saver.save(sess, new_fname)
print("Saved.")
exit()
示例8: convert_linear_attn_to_hier_model
# 需要導入模塊: import util [as 別名]
# 或者: from util import get_config [as 別名]
def convert_linear_attn_to_hier_model():
"""Load non-coverage checkpoint, add initialized extra variables for coverage, and save as new checkpoint"""
tf.logging.info("converting linear model to hier model..")
# initialize an entire coverage model from scratch
sess = tf.Session(config=util.get_config())
print("initializing everything...")
sess.run(tf.global_variables_initializer())
# load all non-coverage weights from checkpoint
saver = tf.train.Saver([v for v in tf.global_variables(
) if "Linear--Section-Features" not in v.name and "v_sec" not in v.name and "Adagrad" not in v.name])
print("restoring variables...")
curr_ckpt = util.load_ckpt(saver, sess)
print("restored.")
# save this model and quit
new_fname = curr_ckpt
print(("saving model to %s..." % (new_fname)))
new_saver = tf.train.Saver() # this one will save all variables that now exist
new_saver.save(sess, new_fname)
print("saved.")
exit()
示例9: setup_training_generator
# 需要導入模塊: import util [as 別名]
# 或者: from util import get_config [as 別名]
def setup_training_generator(model):
"""Does setup before starting training (run_training)"""
train_dir = os.path.join(FLAGS.log_root, "train-generator")
if not os.path.exists(train_dir): os.makedirs(train_dir)
model.build_graph() # build the graph
saver = tf.train.Saver(max_to_keep=20) # we use this to load checkpoints for decoding
sess = tf.Session(config=util.get_config())
#sess.run(tf.train.Saver(max_to_keep=20))
#init = tf.global_variables_initializer()
#sess.run(init)
# Load an initial checkpoint to use for decoding
util.load_ckpt(saver, sess, ckpt_dir="train-generator")
return sess, saver,train_dir
示例10: setup_training_discriminator
# 需要導入模塊: import util [as 別名]
# 或者: from util import get_config [as 別名]
def setup_training_discriminator(model):
"""Does setup before starting training (run_training)"""
train_dir = os.path.join(FLAGS.log_root, "train-discriminator")
if not os.path.exists(train_dir): os.makedirs(train_dir)
model.build_graph() # build the graph
saver = tf.train.Saver(max_to_keep=20) # we use this to load checkpoints for decoding
sess = tf.Session(config=util.get_config())
#init = tf.global_variables_initializer()
#sess.run(init)
util.load_ckpt(saver, sess, ckpt_dir="train-discriminator")
return sess, saver,train_dir
示例11: init_cmdb
# 需要導入模塊: import util [as 別名]
# 或者: from util import get_config [as 別名]
def init_cmdb():
try:
# 取host (在cmdb_host表裏)
# fields = ['id', 'hostname', 'ip', 'vm_status', 'st', 'uuid', 'manufacturers', 'server_type', 'server_cpu', 'os',
# 'server_disk', 'server_mem', 'mac_address', 'manufacture_date', 'check_update_time', 'server_purpose',
# 'server_run', 'expire', 'server_up_time']
fields = ['id','hostname','ip']
# 將角色對應的p_id都轉為name,最終返回的結果p_id的值都是name
hosts = db.Cursor(util.get_config(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'service.conf'),
'api')).get_results('cmdb_host', fields)
for h in hosts:
data = {'cmdb_hostid': h['id']}
where = {'ip': h['ip']}
result = db.Cursor(
util.get_config(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'service.conf'),
'api')).execute_update_sql('zbhost', data, where)
# 更新到cache表, ip
except:
return ""
示例12: init_zabbix
# 需要導入模塊: import util [as 別名]
# 或者: from util import get_config [as 別名]
def init_zabbix():
try:
# 第一步 取出所有host,要ip,host,id
# zb_hosts = app.config['zabbix'].get_hosts()
zb_hosts = zabbix_api.Zabbix(
util.get_config(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'service.conf'),
'zabbix')).get_hosts()
zb_hosts_interface = zabbix_api.Zabbix(
util.get_config(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'service.conf'),
'zabbix')).get_interface([z['hostid'] for z in zb_hosts])
data = []
ret = []
for h in zb_hosts:
h['ip'] = zb_hosts_interface[h['hostid']]
data.append(h)
###數據插入數據庫
for i in data:
result = db.Cursor(
util.get_config(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'service.conf'),
'api')).execute_insert_sql('zbhost', i)
except:
return ""
示例13: create_zabbix_host
# 需要導入模塊: import util [as 別名]
# 或者: from util import get_config [as 別名]
def create_zabbix_host(hostid, groupid):
ret = []
for host in hostid:
data = {
"host": host,
"interfaces": [
{
"type": 1,
"main": 1,
"useip": 1,
"ip": host,
"dns": "",
"port": "10050"
}
],
"groups": [
{
"groupid": groupid
}
]
}
ret.append(zabbix_api.Zabbix(
util.get_config(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'service.conf'),
'zabbix')).create_host(data))
return ret
示例14: create_maintenance
# 需要導入模塊: import util [as 別名]
# 或者: from util import get_config [as 別名]
def create_maintenance(name, start, stop, hostids, time):
data = {
"name": name,
"active_since": start,
"active_till": stop,
"hostids": hostids,
"timeperiods": [
{
"timeperiod_type": 0,
"period": time
}
]
}
ret = zabbix_api.Zabbix(
util.get_config(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'service.conf'),
'zabbix')).create_maintenance(data)
return ret
示例15: zbhost_select
# 需要導入模塊: import util [as 別名]
# 或者: from util import get_config [as 別名]
def zbhost_select(request):
datadict = {}
ret = []
# zbhost表關聯cmdb_host by zhoux
init()
# update by zhouzx (delete 字段 host)
fields = ['id', 'cmdb_hostid', 'hostid', 'host', 'ip']
zabbix_hosts = db.Cursor(util.get_config(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'service.conf'),'api')).get_results('zbhost', fields)
hostid = [str(zb["cmdb_hostid"]) for zb in zabbix_hosts]
server_hosts = db.Cursor(util.get_config(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'service.conf'),'api')).get_results('cmdb_host', ["id"])
for i in server_hosts:
if str(i["id"]) not in hostid:
datadict["id"] = i["id"]
# all_host = app.config['cursor'].get_results('cmdb_host',["ip"],datadict)
get_ip = db.Cursor(util.get_config(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'service.conf'),'api')).get_where_results('cmdb_host', ["id", "ip"], datadict)
ret.append(get_ip[0])
return json.dumps({'code': 0, 'result': ret})