def recog(fname_or_list, train=None): """ 识别 demo,输入一个或多个视频文件路径,返回识别结果 """ if train is None: train = trainer(is_recog=True) train.saver.restore(train.sess, train.model_fname) if not isinstance(fname_or_list, list): fname_or_list = [fname_or_list] with timer('识别视频') as t: probs, labels = train.recog(fname_or_list) delta = t.duration() is_all_test_set = False if fname_or_list == train.batch_generator.test_fname_list: is_all_test_set = True top_accs = [0 for _ in range(5)] for i in range(len(probs)): print('--------------------------------------------------') fname = fname_or_list[i] prob = probs[i] label = labels[i] cls_name = train.batch_generator.cls_list[label] str_format = '%s 的预测标签为:%d,预测类别为:%s' % (fname, label, cls_name) print(str_format) prob = prob.tolist() if is_all_test_set: true_label = train.batch_generator.test_fname_to_label[fname] print('Top-5 预测概率值分别为:') top_5_index = np.argsort(prob)[::-1][:5] for i in range(0, len(top_5_index), 2): index = top_5_index[i] if is_all_test_set: if true_label in top_5_index[:i+1]: top_accs[i] += 1 str_format = '标签:%d - 类别名:%s - 概率值:%f' cls_name = train.batch_generator.cls_list[index] p = prob[index] print(str_format % (index, cls_name, p)) print('--------------------------------------------------') print('以上为所有输入视频的预测标签、类别名和预测概率值') print('总视频数为:%d' % len(fname_or_list)) print('视频总用时:%.3f' % delta) speed = delta / len(fname_or_list) print('识别平均速度为:%.3f sec/视频' % speed) if is_all_test_set: print('++++++++++++++++++++++++++++++++++++++++++++++++++') print('当前使用所有测试集作为演示,可计算准确率,准确率如下:') for i in range(0, len(top_accs), 2): print('Top-%d准确率为:%.4f' % (i+1, top_accs[i] / len(fname_or_list))) train.close()
import sys import bmp import prep import tools import solver import postpro import deformed import gallery import version import prob import copy import plast import gc #start timer TIME = tools.timer() #welcome message print("") print("GRoT> ver. " + version.get() + ", [Graficzny Rozwiązywacz Tarcz]") print("................................................\n") #read optional command line arguments for input and output path folder PROJECT_PATH = False #project will contain input bmp image and input.txt with parameters RESULT_PATH = False #result will contain output of grot args = sys.argv if len(args) > 1: for i in range(len(args)): if args[i] == "-i": PROJECT_PATH = args[i + 1]
if __name__ == '__main__': # verify GPU is available if not cuda.is_available(): raise CudaSupportError("No CUDA-compatible device found") # initialize coordinate grid (in degrees) ha0 = 30. dec0 = 45. dhacosdec = np.linspace(-.5, .5, 128, dtype=np.float32) ddec = np.linspace(-.5, .5, 128, dtype=np.float32) dHACOSDEC, dDEC = np.meshgrid(dhacosdec, ddec) # run beamformer with timer('GPU'): bf_gpu = BeamformerGPU(ha0, dec0, dHACOSDEC, dDEC) # bf_gpu.tabs shape is (ntab, nfreq, ndec, nha) # select one dec bf_gpu.tabs = bf_gpu.tabs[:, :, 63] # plot a few tabs tabs_to_plot = [0, 3, 6, 9] fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(8, 8), sharex=True, sharey=True) axes = axes.flatten() X, Y = np.meshgrid(dhacosdec, bf_gpu.freqs)
from tools import timer from datetime import datetime # print(str(sys.argv)) # try: # s = sys.argv[1] # except: # pass # print(s) # exit() col_news = db["news"] col_rss = db["rss"] col_rss_log = db["rss_log"] t = timer() # col_rss = db['rss'] # for item in rss_links: # item['handy'] = 1 # item['active'] = 1 # col_rss.insert(item) # exit() from lxml import etree parser = etree.HTMLParser() tree = etree.parse( "http://www.dailymail.co.uk/sport/football/article-3437261/Real-Madrid-just-11-fans-attend-win-Granada-Spanish-averse-travelling-away-games.html?ITO=1490&ns_mchannel=rss&ns_campaign=1490", parser,
target = target[:10000] test = test[:10000] # Actual Run Code lable_group = LabelEncoder() Y = lable_group.fit_transform(target) # 变成一个列表 classes_ = lable_group.classes_ print('Y\n', Y) print('classes_\n', classes_) # enter the number of folds from xgb.cv ntest = test.shape[0] folds = 5 early_stopping = 50 oof_test = np.zeros((ntest, 6)) start_time = timer(None) # Load data set and target values # test = test.loc[:, ~test.columns.duplicated()] # print('test\n', test) d_test = xgb.DMatrix(test.values) # In[ ]: # set up KFold that matches xgb.cv number of folds kf = StratifiedKFold(n_splits=folds, random_state=0) # Start the CV acc = [] for i, (train_index, test_index) in enumerate(kf.split(train, Y)):
from tools import timer from datetime import datetime # print(str(sys.argv)) # try: # s = sys.argv[1] # except: # pass # print(s) # exit() col_news = db['news'] col_rss = db['rss'] col_rss_log = db['rss_log'] t = timer() # col_rss = db['rss'] # for item in rss_links: # item['handy'] = 1 # item['active'] = 1 # col_rss.insert(item) # exit() from lxml import etree parser = etree.HTMLParser() tree = etree.parse("http://www.dailymail.co.uk/sport/football/article-3437261/Real-Madrid-just-11-fans-attend-win-Granada-Spanish-averse-travelling-away-games.html?ITO=1490&ns_mchannel=rss&ns_campaign=1490", parser) print(tree)
# reference frequency for dedispersion, use highest frequency ref_freq = freqs.max() # construct dm range to search around known value dm_offsets = np.arange(-16, 16, .1, dtype=np.float32) ndm = len(dm_offsets) print("CUDA info:") cuda.detect() print("DMs: {}".format(ndm)) print("Freqs: {}".format(nfreq)) print("Times: {}".format(ntime)) # serial CPU. CPU is assumed to be right with timer('CPU'): truth = dedisp_cpu(data, dm_offsets, freqs) # Parallelized CPU. with timer('CPU parallel'): cpu_par = dedisp_cpu_par(data, dm_offsets, freqs) assert np.allclose(cpu_par, truth, atol=1E-6) # GPU gpu = cuda.get_current_device() nthread = (gpu.WARP_SIZE, gpu.WARP_SIZE) nx = math.ceil(ndm / nthread[0]) ny = math.ceil(ntime / nthread[1]) nblock = (nx, ny) output_gpu = np.empty((ndm, ntime), dtype=np.float32)
top_accs[i] += 1 str_format = '标签:%d - 类别名:%s - 概率值:%f' cls_name = train.batch_generator.cls_list[index] p = prob[index] print(str_format % (index, cls_name, p)) print('--------------------------------------------------') print('以上为所有输入视频的预测标签、类别名和预测概率值') print('总视频数为:%d' % len(fname_or_list)) print('视频总用时:%.3f' % delta) speed = delta / len(fname_or_list) print('识别平均速度为:%.3f sec/视频' % speed) if is_all_test_set: print('++++++++++++++++++++++++++++++++++++++++++++++++++') print('当前使用所有测试集作为演示,可计算准确率,准确率如下:') for i in range(0, len(top_accs), 2): print('Top-%d准确率为:%.4f' % (i+1, top_accs[i] / len(fname_or_list))) train.close() if __name__ == '__main__': fname_or_list = sys.argv[1:] with timer('恢复模型和参数'): train = trainer(is_recog=True) if len(fname_or_list) == 0: print('没有指定视频,使用所有测试集作为演示') fname_or_list = train.batch_generator.test_fname_list train.saver.restore(train.sess, train.model_fname) recog(fname_or_list, train=train)
def main(restore=True): with tools.timer('build model'): train = trainer() with tools.timer('train'): train.train(restore=restore) train.close()