async def spectate(ctx): member = ctx.message.author player = models.Player() team = models.Team() try: player.custom_load("discord_id = ?", (str(member.id), )) team.load(player.team_id) except Exception as e: await ctx.send( "I think you're already out of the game, {}. If you think this was a mistake, please talk to a Lord or the King" .format(member.mention)) logging.error(e) return # Remove flair from user role = get(member.guild.roles, name=team.name) await member.remove_roles(role, reason='Player left game') # Add spectator role role = get(member.guild.roles, name='Spectator') await member.add_roles(role, reason='Player left game') player.delete() models.save() logging.info("{} has switched to spectating".format(member.id)) await ctx.send("{}, you're now a spectator. Enjoy the show!".format( member.mention))
async def check_for_new_logs(): while True: if helpers.get_game_day( ) > config['game_length'] and config['game_ongoing']: await end_game() t = models.Team_list() t.custom_load("team_id > ?", (0, )) for team in t.items: if team.current_location_id == 0 and config['game_ongoing']: await end_game() logs = models.Log_list() logs.custom_load("sent = ?", (0, )) if len(logs.items) > 0: logging.info("Found {} new logs, attempting to send...".format( len(logs.items))) # Try to send them and die inside. try: for log in logs.items: ch = get(client.get_all_channels(), id=log.target_channel_id) await ch.send(log.msg) log.sent = 1 log.update() models.save() except AttributeError: logging.error( "We can't see the channel yet. We'll get 'em next time.") await asyncio.sleep(5)
async def scramble(ctx): guild = ctx.message.guild logging.info(guild) players = models.Player_list() players.load_all() for p in players.items: old_team_id = p.team_id # Pick a number & update player team_id = randint(1, 3) if old_team_id != team_id: p.team_id = team_id p.update() old_team = models.Team() old_team.load(old_team_id) team = models.Team() team.load(team_id) # Clear/Assign role old_team_role = get(guild.roles, name=old_team.name) team_role = get(guild.roles, name=team.name) member = guild.get_member(int(p.discord_id)) if member is None: logging.info( "Player w/ id {} not found. Maybe they left the server.". format(p.discord_id)) continue await member.remove_roles(old_team_role, reason="Automated Team Scramble") await member.add_roles(team_role, reason="Automated Team Scramble") logging.info("{} (ID:{}) moved from {} to {}".format( member.nick, p.discord_id, old_team.name, team.name)) await asyncio.sleep(1) models.save() logging.info("Scramble complete")
async def on_member_join(member): pa_chan = get(member.guild.text_channels, name="player-assignments") ins_chan = get(member.guild.text_channels, name="instructions") # Assign the new member to one of the three teams randomly # FIXME Get number of teams through the DB and not hardcode a 3 team_id = randint(1, 3) t = models.Team() t.load(team_id) # Add flair to user role = get(member.guild.roles, name=t.name) await member.add_roles(role) # Create new Player record. p = models.Player() # First check if they already exist try: p.custom_load("discord_id = ?", (member.id, )) t.load(p.team_id) await pa_chan.send("Welcome back, {}! the **{}** missed you!".format( member.mention, t.name)) return except Exception: pass p.discord_id = member.id p.team_id = team_id p.coins = config['starting_coins'] p.last_active_day = 0 p.shares = 100 p.insert() models.save() # Post message to player-assignments channel await pa_chan.send("Welcome, {}! You have been assigned to the **{}**!\n\ Make sure to check out the {} and good luck!".format( member.mention, t.name, ins_chan.mention))
def crawl_jobs(project): response = requests.get('http://localhost:6800/listspiders.json?project=' + project) subject = distributed_crawl() path = subject.db_path() save(response.json(), path) spiders = subject.all('spiders') return render_template('list.html',spiders=spiders)
def pay_players(): teams = models.Team_list() teams.custom_load("team_id > ?", (0, )) for t in teams.items: # load all the players players = models.Player_list() players.custom_load("team_id = ?", (t.team_id, )) # Still the dumb Loadall HACK total_team_shares = sum([p.shares for p in players.items]) share_value = config['daily_team_coins'] // total_team_shares # pay 'em for player in players.items: # add daily salary player.coins += share_value * player.shares # get THIS PLAYER's payments from TODAY for THIS PLAYER's TEAM that # WEREN'T put toward the current location (for refunds) models.c.execute( "SELECT SUM(amount) FROM Payment p LEFT JOIN LocationEdge le ON(p.location_edge = le.edge_id) WHERE player_id = ? AND team_id = ? AND time = ? AND end_location_id != ?", (player.player_id, player.team_id, helpers.get_game_day() - 1, t.current_location_id)) refund = models.c.fetchone()[0] if refund is None: refund = 0 player.coins += int(refund * (config['refund_percentage'] / 100)) player.update() models.save()
def super_train(args, built_model, status_track): # take out the parts that self_play needs from the model X, Y, Z, _, _, params, loss = built_model with tf.name_scope("train"): if args.which_cycle == 0: lr = 1e-2 else: lr = 1e-3 train_step = tf.train.AdamOptimizer(lr).minimize(loss) with tf.Session() as sess: sess.run(tf.global_variables_initializer()) model_dir = status_track.get_sl_starter() assert (args.save_dir is not None) and (model_dir is not None), "save_dir and model_dir needs to be specified for super_training" sess.run(load(params, os.path.join(args.save_dir, model_dir))) print("loaded model {} at dir {} as super_training starter".format(args.save_dir, model_dir)) # data for supervised training dump_trace = os.path.join(args.dump_dir, args.dump_file) with open(dump_trace, 'rb') as sl_file: sl_Buffer = pickle.load(sl_file) # supervised training cycle for i in range(args.sl_num_steps + 1): batch = sl_Buffer.sample(args.sl_nbatch) feed_dict = { X: batch[0], Y: batch[1], Z: batch[2] } sess.run(train_step, feed_dict) if i > 0 and i % args.sl_ncheckpoint == 0: new_model_dir = status_track.generate_new_model() print("checkpoint model {}".format(new_model_dir)) ps = sess.run(params) save(ps, os.path.join(args.save_dir, new_model_dir))
def save_checkpoint(name): cycle = ('-cycle%d' % (epoch // args.lr_scheduler_step_size)) if args.lr_scheduler == 'clr' else '' model_name = name + '-model' model_file_name = '%d-%s-%s%s.pth' % (start_timestamp, model_name, full_name, cycle) model_file = models_dir / model_file_name models.save(model, model_file) mode_file_simple = Path(models_dir / (model_name + '-%s%s.pth' % (args.data_fold, cycle))) if mode_file_simple.is_symlink() or mode_file_simple.exists(): mode_file_simple.unlink() mode_file_simple.symlink_to(model_file.relative_to(mode_file_simple.parent)) checkpoint = { 'epoch': epoch, 'step': global_step, 'model_file': str(model_file), 'best_loss': best_loss, 'best_metric': best_metric, 'best_accuracy': best_accuracy, 'optimizer': optimizer.state_dict(), 'lr_scheduler': lr_scheduler.state_dict() } checkpoint_filename = name + '-checkpoint-%s%s.pth' % (full_name, cycle) checkpoint_file = checkpoint_dir / checkpoint_filename torch.save(checkpoint, checkpoint_file) checkpoint_file_simple = Path(checkpoint_dir / (name + '-checkpoint-%s%s.pth' % (args.data_fold, cycle))) if checkpoint_file_simple.is_symlink() or checkpoint_file_simple.exists(): checkpoint_file_simple.unlink() checkpoint_file_simple.symlink_to(checkpoint_file.relative_to(checkpoint_file_simple.parent))
def run(self, save_path: str): epoch = 0 iteration = 0 current_loss = numpy.inf while epoch < self.num_epochs: epoch += 1 for batch_index in range(self.num_training_batches): iteration += 1 current_loss = self.train(batch_index) print('Iteration %i, loss %f%%' % (iteration, current_loss * 100)) is_new_best, stopping_criterion_met = self.evaluation_strategy.apply( epoch, iteration, current_loss ) if is_new_best: models.save(self.model, save_path) if stopping_criterion_met: print('Early stopping criterion met.') return
def route_message(request): username = current_user(request) # 如果此时用户未登录,重定向到 '/' if username == '游客': return redirect('/login') # 判断 POST 请求 if request.method == 'POST': # 先加载原有数据 form = request.form() t = Message.new(form) # 加个时间 t.time = current_time() item = t.saveMessage() save(item, 'data/Message.txt') # 将 list 转换成 str body = templateM('message.html', messages=item) elif request.method == 'GET': # 也就是说,当我第一次访问 http://localhost:3000/messages 时,会先发送 GET 请求 # 定向到了新的 url # http://localhost:3000/messages?message=gua if any(request.query) == False: # 说明是进入网页的时候提交的 GET 请求 # 提取出现有的 Message. path = 'data/Message.txt' data = load(path) body = templateM('message.html', messages=data) header = 'HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n' r = header + '\r\n' + body return r.encode(encoding='utf-8')
def reset(): if PI: kmt.reset() mod4ko.reset() Relay.query.update(dict(is_on=False)) WateringEvent.query.update(dict(in_progress=False)) save()
async def pay(ctx, target_location, amount): if not config['game_ongoing']: return amount = int(amount) # dumb. member = ctx.message.author p = models.Player() try: p.custom_load("discord_id = ?", (member.id, )) except Exception: await ctx.send("I don't have you listed as a player, {}\n\ If you believe this is an error, please talk to a Lord or the King" .format(member.mention)) return # Make sure player has enough coins!!! if amount < 1: await ctx.send("You can't pay 0 or negative coins, {}".format( member.mention)) return elif amount > p.coins: await ctx.send("{}, you don't have enough coins!".format( member.mention)) return # Get team, current location id, available locations t = models.Team() t.load(p.team_id) current_loc = t.current_location_id avail_locs = graphanalyzer.get_next_location_list(t.team_id) # Make sure it's a valid target location. if target_location.lower() not in (name.lower() for name in avail_locs.keys()): await ctx.send( "I don't think {} is a valid location. Maybe you mistyped it?". format(target_location)) return # Get the ID for the target location... target_loc = models.Location() target_loc.custom_load("name = ? COLLATE NOCASE", (target_location, )) edge = models.LocationEdge() edge.custom_load("start_location_id = ? AND end_location_id = ?", ( current_loc, target_loc.location_id, )) # Store the payment in the db payment = models.Payment() payment.player_id = p.player_id payment.team_id = p.team_id payment.amount = amount payment.location_edge = edge.edge_id payment.time = helpers.get_game_day() payment.insert() # Remove coins from player's account. p.coins -= amount p.last_active_day = helpers.get_game_day() p.update() models.save() # Send confirmation message. await ctx.send("{} has paid **{}** coins toward **{}**".format( member.mention, amount, target_loc.name))
def rm_good(good_id): if good_id not in models.goods: return errcode.GOOD_NOT_EXISTS del models.goods[good_id] models.save() return errcode.OK
async def team(ctx): if not config['game_ongoing']: return member = ctx.message.author try: p = models.Player() p.custom_load("discord_id = ?", (member.id, )) if p.last_active_day != helpers.get_game_day(): p.last_active_day = helpers.get_game_day() p.update() models.save() except Exception: await ctx.send("I don't think you're playing, {}\n\ (If you think this is a mistake, please talk to a Lord or the King)" .format(member.mention)) return t = models.Team() t.load(p.team_id) l = models.Location() l.load(t.current_location_id) funding_table = paymentreducer.get_funding_table(p.team_id, helpers.get_game_day()) await ctx.send( "Your team is in **{}**, with at least **{}km** to go!\nHere is how today's funding is going:\n{}" .format( l.name, graphanalyzer.dijkstra(graphanalyzer.graph, t.current_location_id, 0), "```" + funding_table + "```"))
def spider_state(): response = requests.get('http://localhost:6800/listjobs.json?project=distributed_crawl') state = jobs() path = state.db_path() save(response.json(), path) pending = state.all('pending') running = state.all('running') finish = state.all('finished') return render_template('state.html', pending=pending, running=running, finish=finish)
def ten_minute_warning(): if not config['game_ongoing']: return l = models.Log() l.date = str(datetime.now()) l.game_day = helpers.get_game_day() l.msg = "10 minutes remaining in the day! Get those payments in!!!" l.target_channel_id = config['channels']['progress-announcements'] l.insert() models.save()
def add_type(type_name, img_id, show_index=1): for t in models.types.values(): if t.type_name == type_name: return errcode.TYPE_NAME_REPEATED t = models.GoodType(get_id(list(models.types.keys())), type_name, show_index, img_id) models.types[t.id] = t models.save() return errcode.OK
def self_play(args, built_model, status_track): # take out the parts that self_play need from the model X, _, _, p, v, params, _ = built_model # within a tensorflow session, run MCT objects with model with tf.Session() as sess: sess.run(tf.global_variables_initializer()) model_dir = status_track.get_model_dir() if (args.save_dir is not None) and (model_dir is not None): sess.run(load(params, os.path.join(args.save_dir, model_dir))) print("loaded model {} at dir {} for selfplay".format(args.save_dir, model_dir)) else: # this is the initial random parameter! let's save it in hard drive! ps = sess.run(params) model_dir = status_track.generate_new_model() save(ps, os.path.join(args.save_dir, model_dir)) # initialize a list of MCT and run self_play MCTList = [] for i in status_track.get_nbatch_index(args.nbatch, args.n_train_files): MCTList.append(MCT(args.train_path, i, args.max_clause, args.max_var, args.nrepeat, tau = lambda x: 1.0 if x <= 30 else 0.0001, resign = 400)) pi_matrix = np.zeros((args.nbatch, 2 * args.max_var), dtype = np.float32) v_array = np.zeros((args.nbatch,), dtype = np.float32) needMore = np.ones((args.nbatch,), dtype = np.bool) while True: states = [] pi_v_index = 0 for i in range(args.nbatch): if needMore[i]: temp = MCTList[i].get_state(pi_matrix[pi_v_index], v_array[pi_v_index]) pi_v_index += 1 if temp is None: needMore[i] = False else: states.append(temp) if not np.any(needMore): break pi_matrix, v_array = sess.run([p, v], feed_dict = {X: np.asarray(states, dtype = np.float32)}) print("loop finished and save Pi graph to slBuffer") # bring sl_buffer to memory os.makedirs(args.dump_dir, exist_ok = True) dump_trace = os.path.join(args.dump_dir, args.dump_file) if os.path.isfile(dump_trace): with open(dump_trace, 'rb') as sl_file: sl_Buffer = pickle.load(sl_file) else: sl_Buffer = slBuffer_allFile(args.sl_buffer_size, args.train_path, args.n_train_files) # write in sl_buffer for i in range(args.nbatch): MCTList[i].write_data_to_buffer(sl_Buffer) # write sl_buffer back to disk with open(dump_trace, 'wb') as sl_file: pickle.dump(sl_Buffer, sl_file, -1)
def update_shares(): players = models.Player_list() players.load_all() for player in players.items: days_since_active = helpers.get_game_day() - player.last_active_day if days_since_active < len(config['afk_falloff']): player.shares = config['afk_falloff'][days_since_active] else: player.shares = 0 player.update() models.save()
def hello(): #Get this IP address of the viewer viewerIp = request.remote_addr #Create a new Viewer object to save in the database viewer = models.Viewer(ip=viewerIp) #Save the viewer in the database using our model models.save(viewer) #Get the count of all viewers in the database count = models.count(models.Viewer) #Return the string of how many users have accessed this page return "Hello #{0}\n".format(count)
def add_image(req_file): origin_filename, file_ext = os.path.splitext(req_file.filename) g_id = get_id(list(models.images.keys())) g_filename = str(g_id) + file_ext save_filename = os.path.join(config['image_path'], g_filename) req_file.save(save_filename) g = models.Image(g_id, g_filename, req_file.filename) models.images[g.id] = g models.save() return errcode.OK
def store_fractal(request): if request.method == "POST": jsonin = json.loads(request.body) key = genHash(jsonin["fractal64"]) models.save(key, jsonin) #models.cleanSlate() return HttpResponse(json.dumps({'fractalKey': key})) return HttpResponse("404")
def test_errs(self): """ Test Errors """ with self.assertRaises(AttributeError): FileStorage.__objects FileStorage.__File_path with self.assertRaises(TypeError): models.storage.new() models.storage.new(self, BaseModel()) models.save(BaseModel()) models.reload(BaseModel()) models.all(BaseModel())
def test_errs(self): """Test most mal usage of FileStorage methods""" b1 = BaseModel() with self.assertRaises(AttributeError): FileStorage.__objects FileStorage.__File_path with self.assertRaises(TypeError): models.storage.new() models.storage.new(self, b1) models.save(b1) models.reload(b1) models.all(b1)
def rm_type(type_id): if type_id not in models.types: return errcode.TYPE_NOT_EXISTS keys = list(models.goods.keys()) for key in keys: g = models.goods[key] if g.type_id == type_id: print("del ", g.id) del models.goods[key] del models.types[type_id] models.save() return errcode.OK
def save(self, request): """ Add or update a purchase """ purchaseModel = models.save(request) product = purchaseModel.product.get() supplier = purchaseModel.supplier.get() return PurchaseGetMessage( id=purchaseModel.key.id(), supplier=supplierMessages.SupplierGetMessage( id=supplier.key.id(), name=supplier.name, created_date=supplier.created_date), product=productMessages.ProductGetMessage( id=product.key.id(), code=product.code, name=product.name, created_date=product.created_date), quantity=purchaseModel.quantity, purchase_date=purchaseModel.purchase_date, received_date=purchaseModel.received_date, cost=purchaseModel.cost, total_cost=purchaseModel.total_cost, exchange_dollar=purchaseModel.exchange_dollar, cost_dollar=purchaseModel.cost_dollar, total_cost_dollar=purchaseModel.total_cost_dollar, shipping_cost=purchaseModel.shipping_cost, track_code=purchaseModel.track_code, invoice=purchaseModel.invoice, payment_date=purchaseModel.payment_date, purchase_link=purchaseModel.purchase_link, created_date=purchaseModel.created_date)
def save(self, request): """ Add or update a sale """ saleModel = models.save(request) # Get entities children customerModel = saleModel.customer.get() productModel = saleModel.product.get() # Retornando compra persistida return SaleGetMessage(id=saleModel.key.id(), customer=customer.CustomerGetMessage( id=customerModel.key.id(), name=customerModel.name, email=customerModel.email, phone=customerModel.phone, location=customerModel.location, created_date=customerModel.created_date), product=product.ProductGetMessage( id=productModel.key.id(), code=productModel.code, name=productModel.name, created_date=productModel.created_date), quantity=saleModel.quantity, sale_date=saleModel.sale_date, amount=saleModel.amount, fare=saleModel.fare, net_total=saleModel.net_total, track_code=saleModel.track_code, created_date=saleModel.created_date)
def save(self, request): """ Add or update a sale """ saleModel = models.save(request) # Get entities children customerModel = saleModel.customer.get() productModel = saleModel.product.get() # Retornando compra persistida return SaleGetMessage( id=saleModel.key.id(), customer=customer.CustomerGetMessage( id=customerModel.key.id(), name=customerModel.name, email=customerModel.email, phone=customerModel.phone, location=customerModel.location, created_date=customerModel.created_date ), product=product.ProductGetMessage( id=productModel.key.id(), code=productModel.code, name=productModel.name, created_date=productModel.created_date ), quantity=saleModel.quantity, sale_date=saleModel.sale_date, amount=saleModel.amount, fare=saleModel.fare, net_total=saleModel.net_total, track_code=saleModel.track_code, created_date=saleModel.created_date)
async def me(ctx): if not config['game_ongoing']: return member = ctx.message.author try: p = models.Player() p.custom_load("discord_id = ?", (member.id, )) await ctx.send("{}, you have **{}** coins".format( member.mention, p.coins)) if p.last_active_day != helpers.get_game_day(): p.last_active_day = helpers.get_game_day() p.update() models.save() except Exception: # Show error if user isn't actually playing await ctx.send("I... don't believe you're playing, {}\n\ (If you think this is a mistake, please talk to a Lord or the King)" .format(member.mention))
def _send_to_es(_type, objs, path=data_dir): logger.info('Sending to %i %s pipeline' % (len(objs), _type)) stats = {True: {}, False: {}} passed = stats[True] failed = stats[False] consecutive_fails = 0 result_before = True cmdline_objs = type(objs) is list lava_batch_size = 10 if cmdline_objs: logger.info( 'Command line detected! Duplicates might exist for %i %s index' % (len(objs), _type)) objs = {_id: objs[_id] for _id in range(0, len(objs))} for _id in objs: result = _send(_type, objs[_id], path) stats[result][_id] = objs[_id] # If 3 consecutive fails, Logstash is probably down if not result: consecutive_fails = consecutive_fails + 1 if result == result_before else 0 if consecutive_fails == 3: logger.error( 'Multiple failed attempts to connect to Logstash, aborting...' ) return passed, failed result_before = result # Controls amount of load to send logstash sent = len(passed) + len(failed) if _type == 'lava': if (sent % lava_batch_size) == 0: logger.info( 'Wait a bit to let logstash digest more %i events. Sleeping for %i seconds' % (10, settings.ES_LOAD_INTERVAL)) time.sleep(settings.ES_LOAD_INTERVAL) # Save successfull objs and delete the ones processed correctly if not cmdline_objs: models.save(_type, passed) _unlink_successfull_objs(passed, path) return passed, failed
def register(self, c, addr): while 1: feedback = self.recver(c, addr) if not feedback: return False name = feedback["data"][0] if not name in models.fort_names: models.fort_names.append(name) models.save() self.sender({"tag": "feedback", "data": [True]}, c) return name feedback = self.sender( { "tag": "feedback", "data": [False, "name_taken"] }, c) if not feedback: return False
def create_all_edges(save=False): edges = {} with open('map.txt') as f: for line in f.readlines(): line = line.strip() if line[0] == '#': continue l = line.split('->') key = l[0].strip() values = l[1].strip().split(', ') edges[key] = values for k, v in edges.items(): for loc in v: create_edge(k, loc) if save: models.save()
def main(): # interpret command line arguments if len(sys.argv) <= 1: print( "please specify a model name (e.g. models.baseline.random_handle)") sys.exit(1) module_name = sys.argv[1] hyper_parameters = models.parse_hyper_parameters(sys.argv[2:]) # training model module = importlib.import_module(module_name) print( f"Training {module_name}.Model with hyperparameters {hyper_parameters}" ) model = module.Model(tqdm(data.TRAIN, dynamic_ncols=True), **hyper_parameters) print("Training done!") models.save(model, module_name, hyper_parameters)
def save(self, request): """ Add or update a product. """ ProductModel = models.save(request) return ProductGetMessage( id=ProductModel.key.id(), code=ProductModel.code, name=ProductModel.name, created_date=ProductModel.created_date)
def save(self, request): """ Add or update a supplier. """ supplierModel = models.save(request) return SupplierGetMessage( id=supplierModel.key.id(), name=supplierModel.name, email=supplierModel.email, phone=supplierModel.phone, location=supplierModel.location, created_date=supplierModel.created_date)
def save(self, request): """ Add or update a customer. """ # Save model customerModel = models.save(request) # Transport model to message return CustomerGetMessage( id=customerModel.key.id(), name=customerModel.name, email=customerModel.email, phone=customerModel.phone, location=customerModel.location, created_date=customerModel.created_date)
def save(self, request): """Inclui ou atualiza um fornecedor. """ logging.debug('Executando endpoint para incluir/atualizar um fornecedor') #Cadastrar/atualizar a compra de um fornecedor supplierModel = models.save(request) #Retornando compra persistida return SupplierGetMessage( id = supplierModel.key.id(), name = supplierModel.name, email = supplierModel.email, phone = supplierModel.phone, location = supplierModel.location, created_date = supplierModel.created_date)
import csv from os.path import abspath, dirname, join as join_path from models import save BASE_DIR = dirname(abspath(__file__)) path = join_path(BASE_DIR, "stations", "airport_stations_seed.csv") rows = csv.DictReader(open(path)) save(rows, schema="Municipio", table="Estacao_wu")
from pathlib import Path from torchvision.transforms import Compose from torch.utils.data import DataLoader from transforms import PrepareImageAndMask, PadToNxN, HWCtoCHW from datasets import SaltIdentification parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument("--input", type=str, help='input directory') parser.add_argument("--output", type=str, default='swa_model.pth', help='output model file') parser.add_argument("--batch-size", type=int, default=16, help='batch size') args = parser.parse_args() directory = Path(args.input) files = [f for f in directory.iterdir() if f.suffix == ".pth"] assert(len(files) > 1) net = models.load(files[0]) for i, f in enumerate(files[1:]): net2 = models.load(f) moving_average(net, net2, 1. / (i + 2)) img_size = 128 batch_size = 16 train_transform = Compose([PrepareImageAndMask(), PadToNxN(img_size), HWCtoCHW()]) train_dataset = SaltIdentification(mode='train', transform=train_transform, preload=True) train_dataloader = DataLoader(train_dataset, shuffle=True, batch_size=batch_size, drop_last=True) net.cuda() bn_update(train_dataloader, net) models.save(net, args.output)
# TODO: We should improve the complexity of this function def county_polygon(uf, county_code): for feature in uf_geojson(uf)["features"]: if feature["properties"].get("CD_GEOCODM") == county_code: return geojson.dumps(feature) raise ValueError("{} is not in this geojson: {}.".format(county_code, uf)) def to_row(county): county_code = county['Cod Municipio Completo'] name = county['Nome_Município'] uf = county['Nome_UF'] try: geojson = county_polygon(initials[uf], county_code) print(uf, name, county_code) except ValueError as e: print(e) geojson = '' return dict(county_code=county_code, name=name, geojson=geojson, uf=initials[uf], population=0) BASE_DIR = dirname(abspath(__file__)) path = join_path(BASE_DIR, "DTB_2014_Municipio.csv") rows = Pool().map(to_row, csv.DictReader(open(path))) save(rows, schema="Dengue_global", table="Municipio")