本文整理汇总了Python中network.Network方法的典型用法代码示例。如果您正苦于以下问题:Python network.Network方法的具体用法?Python network.Network怎么用?Python network.Network使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类network
的用法示例。
在下文中一共展示了network.Network方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_population
# 需要导入模块: import network [as 别名]
# 或者: from network import Network [as 别名]
def create_population(self, count):
"""Create a population of random networks.
Args:
count (int): Number of networks to generate, aka the
size of the population
Returns:
(list): Population of network objects
"""
pop = []
for _ in range(0, count):
# Create a random network.
network = Network(self.nn_param_choices)
network.create_random()
# Add the network to our population.
pop.append(network)
return pop
示例2: mutate
# 需要导入模块: import network [as 别名]
# 或者: from network import Network [as 别名]
def mutate(self, network):
"""Randomly mutate one part of the network.
Args:
network (dict): The network parameters to mutate
Returns:
(Network): A randomly mutated network object
"""
# Choose a random key.
mutation = random.choice(list(self.nn_param_choices.keys()))
# Mutate one of the params.
network.network[mutation] = random.choice(self.nn_param_choices[mutation])
return network
示例3: __init__
# 需要导入模块: import network [as 别名]
# 或者: from network import Network [as 别名]
def __init__(self, config):
threading.Thread.__init__(self)
self.daemon = True
self.debug = False
self.config = config
self.network = Network(config)
# network sends responses on that queue
self.network_queue = Queue.Queue()
self.running = False
self.lock = threading.RLock()
# each GUI is a client of the daemon
self.clients = []
self.request_id = 0
self.requests = {}
示例4: main
# 需要导入模块: import network [as 别名]
# 或者: from network import Network [as 别名]
def main(args):
paths = Dataset(args.dataset_path)['abspath']
print('%d images to load.' % len(paths))
assert(len(paths)>0)
# Load model files and config file
network = Network()
network.load_model(args.model_dir)
images = preprocess(paths, network.config, False)
# Run forward pass to calculate embeddings
mu, sigma_sq = network.extract_feature(images, args.batch_size, verbose=True)
feat_pfe = np.concatenate([mu, sigma_sq], axis=1)
lfwtest = LFWTest(paths)
lfwtest.init_standard_proto(args.protocol_path)
accuracy, threshold = lfwtest.test_standard_proto(mu, utils.pair_euc_score)
print('Euclidean (cosine) accuracy: %.5f threshold: %.5f' % (accuracy, threshold))
accuracy, threshold = lfwtest.test_standard_proto(feat_pfe, utils.pair_MLS_score)
print('MLS accuracy: %.5f threshold: %.5f' % (accuracy, threshold))
示例5: load_model
# 需要导入模块: import network [as 别名]
# 或者: from network import Network [as 别名]
def load_model(weight_path, continuous_fine_tuning=False):
weight_path = os.path.abspath(weight_path)
if not os.path.exists(weight_path):
raise RuntimeError("Could not find file: " + weight_path + ". Did you remember to download the pretrained model?")
if weight_path.endswith('.gz'):
with gzip.open(weight_path, 'rb') as f_in:
state = torch.load(f_in, get_device())
else:
state = torch.load(weight_path, get_device())
net = Network()
net.to(net.device)
net.load_state_dict(state['network'])
if continuous_fine_tuning:
net.cft = CFT(state, net)
return net
示例6: two_layer_sigmoid
# 需要导入模块: import network [as 别名]
# 或者: from network import Network [as 别名]
def two_layer_sigmoid():
model = Network()
model.add(Linear('fc1', 784, 256, 0.001))
model.add(Sigmoid('sg1'))
model.add(Linear('fc2', 256, 10, 0.001))
model.add(Sigmoid('sg2'))
config = {
'learning_rate': 0.01,
'weight_decay': 0.005,
'momentum': 0.9,
'batch_size': 100,
'max_epoch': 20,
'disp_freq': 50,
'test_epoch': 5
}
return model, config
示例7: two_layer_relu
# 需要导入模块: import network [as 别名]
# 或者: from network import Network [as 别名]
def two_layer_relu():
model = Network()
model.add(Linear('fc1', 784, 256, 0.001))
model.add(Relu('rl1'))
model.add(Linear('fc2', 256, 10, 0.001))
model.add(Relu('rl2'))
config = {
'learning_rate': 0.0001,
'weight_decay': 0.005,
'momentum': 0.9,
'batch_size': 200,
'max_epoch': 40,
'disp_freq': 50,
'test_epoch': 5
}
return model, config
示例8: three_layer_sigmoid
# 需要导入模块: import network [as 别名]
# 或者: from network import Network [as 别名]
def three_layer_sigmoid():
model = Network()
model.add(Linear('fc1', 784, 256, 0.001))
model.add(Sigmoid('sg1'))
model.add(Linear('fc2', 256, 128, 0.001))
model.add(Sigmoid('sg2'))
model.add(Linear('fc3', 128, 10, 0.001))
model.add(Sigmoid('sg3'))
config = {
'learning_rate': 0.01,
'weight_decay': 0.005,
'momentum': 0.9,
'batch_size': 300,
'max_epoch': 60,
'disp_freq': 50,
'test_epoch': 5
}
return model, config
示例9: three_layer_relu
# 需要导入模块: import network [as 别名]
# 或者: from network import Network [as 别名]
def three_layer_relu():
model = Network()
model.add(Linear('fc1', 784, 256, 0.001))
model.add(Relu('rl1'))
model.add(Linear('fc2', 256, 128, 0.001))
model.add(Relu('rl2'))
model.add(Linear('fc3', 128, 10, 0.001))
model.add(Relu('rl3'))
config = {
'learning_rate': 0.0001,
'weight_decay': 0.005,
'momentum': 0.9,
'batch_size': 300,
'max_epoch': 60,
'disp_freq': 50,
'test_epoch': 5
}
return model, config
示例10: main
# 需要导入模块: import network [as 别名]
# 或者: from network import Network [as 别名]
def main(config):
#Initialize Network
net = Network(config)
data = {}
if config.run_mode == 'train':
data['train'] = load_data(config, 'train')
net.train(data)
if config.run_mode == 'test':
data['test'] = load_data(config, 'test')
net.test(data)
return 0
示例11: test
# 需要导入模块: import network [as 别名]
# 或者: from network import Network [as 别名]
def test():
n = Network(LATENCY * 2)
nodes = [Node(n, i, i%4==0) for i in range(20)]
for i in range(30):
for _ in range(2):
z = random.randrange(20)
n.send_to([1000 + i], z, at=5+i*2)
for i in range(21 * LATENCY):
n.tick()
if i % 10 == 0:
print("Value sets", [sorted(node.seen.keys()) for node in nodes])
countz = {}
maxval = ""
for node in nodes:
if node.honest:
k = str(sorted(node.seen.keys()))
countz[k] = countz.get(k, 0) + 1
if countz[k] > countz.get(maxval, 0):
maxval = k
print("Most popular: %s" % maxval, "with %d agreeing" % countz[maxval])
示例12: breed
# 需要导入模块: import network [as 别名]
# 或者: from network import Network [as 别名]
def breed(self, mother, father):
"""Make two children as parts of their parents.
Args:
mother (dict): Network parameters
father (dict): Network parameters
Returns:
(list): Two network objects
"""
children = []
for _ in range(2):
child = {}
# Loop through the parameters and pick params for the kid.
for param in self.nn_param_choices:
child[param] = random.choice(
[mother.network[param], father.network[param]]
)
# Now create a network object.
network = Network(self.nn_param_choices)
network.create_set(child)
# Randomly mutate some of the children.
if self.mutate_chance > random.random():
network = self.mutate(network)
children.append(network)
return children
示例13: generate_network_list
# 需要导入模块: import network [as 别名]
# 或者: from network import Network [as 别名]
def generate_network_list(nn_param_choices):
"""Generate a list of all possible networks.
Args:
nn_param_choices (dict): The parameter choices
Returns:
networks (list): A list of network objects
"""
networks = []
# This is silly.
for nbn in nn_param_choices['nb_neurons']:
for nbl in nn_param_choices['nb_layers']:
for a in nn_param_choices['activation']:
for o in nn_param_choices['optimizer']:
# Set the parameters.
network = {
'nb_neurons': nbn,
'nb_layers': nbl,
'activation': a,
'optimizer': o,
}
# Instantiate a network object with set parameters.
network_obj = Network()
network_obj.create_set(network)
networks.append(network_obj)
return networks
示例14: main
# 需要导入模块: import network [as 别名]
# 或者: from network import Network [as 别名]
def main(_):
model_dir = util.get_model_dir(conf,
['data_dir', 'sample_dir', 'max_epoch', 'test_step', 'save_step',
'is_train', 'random_seed', 'log_level', 'display', 'runtime_base_dir',
'occlude_start_row', 'num_generated_images'])
util.preprocess_conf(conf)
validate_parameters(conf)
data = 'mnist' if conf.data == 'color-mnist' else conf.data
DATA_DIR = os.path.join(conf.runtime_base_dir, conf.data_dir, data)
SAMPLE_DIR = os.path.join(conf.runtime_base_dir, conf.sample_dir, conf.data, model_dir)
util.check_and_create_dir(DATA_DIR)
util.check_and_create_dir(SAMPLE_DIR)
dataset = get_dataset(DATA_DIR, conf.q_levels)
with tf.Session() as sess:
network = Network(sess, conf, dataset.height, dataset.width, dataset.channels)
stat = Statistic(sess, conf.data, conf.runtime_base_dir, model_dir, tf.trainable_variables())
stat.load_model()
if conf.is_train:
train(dataset, network, stat, SAMPLE_DIR)
else:
generate(network, dataset.height, dataset.width, SAMPLE_DIR)
示例15: __init__
# 需要导入模块: import network [as 别名]
# 或者: from network import Network [as 别名]
def __init__(self, socket, config=None):
if config is None:
config = {} # Do not use mutables as default arguments!
threading.Thread.__init__(self)
self.config = SimpleConfig(config) if type(config) == type({}) else config
self.message_id = 0
self.unanswered_requests = {}
self.subscriptions = {}
self.debug = False
self.lock = threading.Lock()
self.pending_transactions_for_notifications = []
self.callbacks = {}
self.running = True
self.daemon = True
if socket:
self.pipe = util.SocketPipe(socket)
self.network = None
else:
self.network = Network(config)
self.pipe = util.QueuePipe(send_queue=self.network.requests_queue)
self.network.start(self.pipe.get_queue)
for key in ['status','banner','updated','servers','interfaces']:
value = self.network.get_status_value(key)
self.pipe.get_queue.put({'method':'network.status', 'params':[key, value]})
# status variables
self.status = 'connecting'
self.servers = {}
self.banner = ''
self.blockchain_height = 0
self.server_height = 0
self.interfaces = []