Esempio n. 1
0
def execute_selection():
    #Read selection.
    selection = read_selection()
    genTime = get_local_time()
    resultFileName = genTime + ' test_result'
    resultFileName = resultFileName.replace(':', '_')
    #autyPath = os.getcwd()
    autyPath = os.path.dirname(os.path.dirname(__file__))
    #Save the auty path into file.
    pathFilePath = os.path.join(autyPath, 'utils', 'root_path.py')
    writeContent = '# -*- coding: utf-8 -*-\n' + 'autyPath=\'' + autyPath + '\''
    open(pathFilePath, 'w').write(writeContent)
    #Result generation.
    resultFilePath = os.path.join(autyPath, 'results', resultFileName)
    generate_result(
        resultFilePath,
        ('scriptPath', 'detail', 'startTime', 'endTime', 'duration', 'result'))
    for scriptPath in selection:
        result = str_2_tuple(scriptPath)
        startTime = get_specific_time()
        #Execution of scripts.
        ret, result2 = execute_script(scriptPath, autyPath)
        endTime = get_specific_time()
        duration = (endTime - startTime).microseconds * 0.000001
        #Generation of results.
        result = result + result2 + str_2_tuple(startTime) + str_2_tuple(
            endTime) + str_2_tuple(duration) + str_2_tuple(ret)
        generate_result(resultFilePath, result)
Esempio n. 2
0
def main():
    print(outf)
    print("loading dataset ...")
    trainDataset = TrainDataset(name='/data0/niejiangtao/ICIP2019Deraining/train/train.h5')
    batchSize = opt.batchSize_per_gpu * len(device_ids)
    trainLoader = udata.DataLoader(trainDataset, batch_size=batchSize, shuffle=True, num_workers=0)

    testDataset = TestDataset2(name='/data0/niejiangtao/ICIP2019Deraining/test_a/test.h5')
    print('testDataset len : {}'.format(len(testDataset)))
    
    l1_criterion = nn.L1Loss().cuda()
    # mask_criterion = nn.MSELoss().cuda()
    ssim_criterion = SSIM().cuda()
    
    model = UNet_v2(n_channels=3, n_classes=3)
    # model = RESCAN()

    if len(device_ids) > 1:
        model = nn.DataParallel(model, device_ids=device_ids)
    model.cuda()
    
    beta1 = 0.9
    beta2 = 0.999
    optimizer = optim.Adam(filter(lambda p: p.requires_grad, model.parameters()), lr=opt.lr, weight_decay=weight_decay, betas=(beta1, beta2))

    writer = SummaryWriter(outf)

    for epoch in range(opt.epochs):
        start = time.time()
        current_lr = opt.lr / 2**int(epoch / interval)
        for param_group in optimizer.param_groups:
            param_group["lr"] = current_lr
        print("epoch {} learning rate {}".format(epoch, current_lr))

        # test(model, testDataset, None, epoch, writer=writer)
        train_epoch(model, optimizer, trainLoader, l1_criterion, None, ssim_criterion, epoch, writer=writer, radio=radio)

        if (epoch+1) % 5 == 0:
            test(model, testDataset, None, epoch, writer=writer)
        if (epoch+1) % 20 == 0:
            """ torch.save({
                'epoch': epoch,
                'model_state_dict': model.module.state_dict(),
                'optimizer_state_dict': optimizer.state_dict()
            }, os.path.join(outf, 'checkpoint_{}.pth'.format(epoch))) """
            torch.save(model.state_dict(), os.path.join(outf, 'model_{}.pth'.format(epoch)))

        end = time.time()
        print('epoch {} cost {} hour '.format(
            epoch, str((end - start) / (60 * 60))))
            
    torch.save(model.state_dict(), os.path.join(outf, 'model.pth'))
    generate_result(model, outf, testDataset, mat=False, ouput_img=True)
Esempio n. 3
0
def run(fortell_time_str, fortell_zone_str, fortell_index_str, gender, birth):
    fortell_time = datetime.strptime(fortell_time_str, '%Y-%m-%d %H:%M:%S')
    fortell_zone = int(fortell_zone_str)
    fortell_index = int(fortell_index_str)
    gt = todayse(fortell_time, fortell_zone)
    if fortell_index != None:
        gt.set_fortell_hour(fortell_index)
    tmptoday = gt.get_day()
    tmptodayst = tmptoday[0:3]
    tmptodayeb = tmptoday[3:]
    tmphour = gt.get_hour()
    tmphoureb = tmphour[3:]
    tmpgeneral = gt.get_month_general()
    if gender == '1':
        tmpgender = '男'
    else:
        tmpgender = '女'
    tmpbirth = birth
    '''
	print "tmptoday "+tmptoday
	print "tmptodayst "+tmptodayst
	print "tmptodayeb "+tmptodayeb
	print "tmphour"+tmphour
	print "tmphoureb "+tmphoureb	
	'''
    #fortell_time_str = fortell_time.strftime('%Y-%m-%d %H:%M:%S')
    gyl = get_yearloop(tmpgender, tmpbirth, fortell_time_str[0:4])
    tmpblank = gt.get_blank()
    tmpline = "<p>" + tmpgender + '命  ' + gyl.return_res() + "</p>"
    tmpline = tmpline + "<p>起课时间:" + fortell_time_str + "</p>"
    tmpline = tmpline + "<p>占时: " + gt.get_year() + "年 " + gt.get_month(
    ) + "月 " + tmptoday + "日 " + tmphour + "时 " + " 月将" + tmpgeneral + tmpblank + "</p>"
    tmpline = tmpline + "<p>" + gt.get_front_jieqi(
    ) + " " + gt.get_after_jieqi() + "</p>"
    gs = generate_result(tmptodayst, tmptodayeb, tmpgeneral, tmphoureb)
    gs.generate_skyplate()
    gs.generate_four()
    gs.generate_skygeneral()
    gs.generate_trishift()
    output11 = output_results(gs.st, gs.eb, gs.month_general, gs.foretell_hour,
                              gs.skyplate, gs.skygeneral, gs.bottom_four,
                              gs.upper_four, gs.triline)

    tmp_year = gt.get_year()
    tmp_month = gt.get_month()
    global_record_list.set_global_record(0, tmp_year[0:3])
    global_record_list.set_global_record(1, tmp_year[3:])
    global_record_list.set_global_record(2, tmp_month[0:3])
    global_record_list.set_global_record(3, tmp_month[3:])
    global_record_list.set_global_record(6, tmphour[0:3])
    global_record_list.set_global_record(7, tmphour[3:])
    global_record_list.set_global_record(58, tmpblank[17:20])
    global_record_list.set_global_record(59, tmpblank[20:])
    print global_record_list.get_global_record()
    return tmpline + output11.output()
Esempio n. 4
0
def run(
    fortell_time_str,
    fortell_zone,
    fortell_index,
):
    fortell_time = datetime.strptime(fortell_time_str, '%Y-%m-%d %H:%M:%S')
    gt = todayse(fortell_time, fortell_zone)
    if fortell_index != None:
        gt.set_fortell_hour(fortell_index)
    tmptoday = gt.get_day()
    tmptodayst = tmptoday[0:3]
    tmptodayeb = tmptoday[3:]
    tmphour = gt.get_hour()
    tmphoureb = tmphour[3:]
    tmpgeneral = gt.get_month_general()
    '''
	print "tmptoday "+tmptoday
	print "tmptodayst "+tmptodayst
	print "tmptodayeb "+tmptodayeb
	print "tmphour"+tmphour
	print "tmphoureb "+tmphoureb	
	'''
    #fortell_time_str = fortell_time.strftime('%Y-%m-%d %H:%M:%S')
    print "起课时间:" + fortell_time_str
    print "占时: " + gt.get_year() + "年 " + gt.get_month(
    ) + "月 " + tmptoday + "日 " + tmphour + "时 " + " 月将" + tmpgeneral

    gs = generate_result(tmptodayst, tmptodayeb, tmpgeneral, tmphoureb)
    gs.generate_skyplate()
    gs.generate_four()
    gs.generate_skygeneral()
    gs.generate_trishift()
    output11 = output_results(gs.st, gs.eb, gs.month_general, gs.foretell_hour,
                              gs.skyplate, gs.skygeneral, gs.bottom_four,
                              gs.upper_four, gs.triline)
    output11.output()
Esempio n. 5
0
                print(cnt)
                cnt_up += 1000
                # if cnt > 10: break

            if line[0] not in uid_map:
                cursor.execute(
                    "SELECT forward_count, comment_count, like_count "
                    "FROM `weibo_train_data` WHERE uid = '{}';".format(line[0]))
                data = cursor.fetchall()
                if not data:
                    data = [[0, 0, 0]]
                fc_med = []
                cc_med = []
                lc_med = []
                for i in data:
                    fc_med.append(i[0])
                    cc_med.append(i[1])
                    lc_med.append(i[2])
                uid_map[line[0]] = [median(fc_med), median(cc_med), median(lc_med)]

            result.append(
                "{0}\t{1}\t{2:.0f},{3:.0f},{4:.0f}\n".format(line[0], line[1], uid_map[line[0]][0],
                                                             uid_map[line[0]][1], uid_map[line[0]][2]))

    generate_result('../result/weibo_result' + time.strftime('%m-%d', time.localtime(time.time())) + '.txt', result)

    cursor.close()
    cnx.close()
except mysql.connector.Error as err:
    print(err.msg)
Esempio n. 6
0
        for line in query:

            cnt += 1
            if cnt >= cnt_up:
                print(cnt)
                cnt_up += 1000
                # if cnt > 10: break

            if line[0] not in uid_map:
                cursor.execute(
                    "SELECT forward_count, comment_count, like_count "
                    "FROM `weibo_train_data` WHERE uid = '{}';".format(
                        line[0]))
                data = cursor.fetchall()
                if not data:
                    data = [[0, 0, 0]]
                uid_map[line[0]] = max_precision(data)

            result.append("{0}\t{1}\t{2:.0f},{3:.0f},{4:.0f}\n".format(
                line[0], line[1], uid_map[line[0]][0], uid_map[line[0]][1],
                uid_map[line[0]][2]))

    generate_result(
        '../result/weibo_result' +
        time.strftime('%m-%d', time.localtime(time.time())) + '.txt', result)

    cursor.close()
    cnx.close()
except mysql.connector.Error as err:
    print(err.msg)
Esempio n. 7
0
		fortell_time = datetime.now()
		fortell_time_str = fortell_time.strftime('%Y-%m-%d %H:%M:%S')			
	gt = todayse(fortell_time, fortell_zone)

	if fortell_index != None:
		gt.set_fortell_hour(fortell_index)
	tmptoday = gt.get_day()
	tmptodayst = tmptoday[0:3]
	tmptodayeb = tmptoday[3:]
	tmphour = gt.get_hour()
	tmphoureb = tmphour[3:]
	tmpgeneral = gt.get_month_general()
	'''
	print "tmptoday "+tmptoday
	print "tmptodayst "+tmptodayst
	print "tmptodayeb "+tmptodayeb
	print "tmphour"+tmphour
	print "tmphoureb "+tmphoureb	
	'''
	print "起课时间:"+	fortell_time_str
	print "占时: "+gt.get_year()+"年 "+gt.get_month()+"月 "+tmptoday+"日 "+tmphour+ "时 " + " 月将"+ tmpgeneral
	
	gs = generate_result(tmptodayst,tmptodayeb,tmpgeneral,tmphoureb)
	gs.generate_skyplate()
	gs.generate_four()
	gs.generate_skygeneral()
	gs.generate_trishift()	
	output11 = output_results(gs.st, gs.eb, gs.month_general, gs.foretell_hour, gs.skyplate, gs.skygeneral, gs.bottom_four, gs.upper_four, gs.triline)
	output11.output()