def predict(data_path, model_path, config ): image_size = config.image_size model = keras.models.load_model(model_path) for image_name in os.listdir(data_path): image_path = get_path(data_path, image_name) image = cv2.imread(image_path) image = cv2.resize(image, (image_size, image_size)) predictions = model.predict([image.reshape(-1, image_size, image_size, 3)]) class_id = np.argmax(predictions) class_name = get_category(config, class_id) print(image_name + ': Prediction ' + class_name) plt.imshow(image, cmap=plt.cm.binary) plt.xlabel(class_name) if config.display_plot: plt.show()
db = client.test @functools.lru_cache(maxsize=1000000) def get_ad_info(aid): ad_info = db.ad_info.find_one({"AdID": aid}) return trans_ad_info(ad_info) uid_cnt_dict = read_dump("data/uid_cnt.dump") adid_cnt_dict = read_dump("data/adid_cnt.dump") ipid_cnt_dict = read_dump("data/ipid_cnt.dump") query_cnt_dict = read_dump("data/query_cnt.dump") title_cnt_dict = read_dump("data/title_cnt.dump") query_param_cnt_dict = read_dump("data/query_param_cnt.dump") ad_param_cnt_dict = read_dump("data/ad_param_cnt.dump") user_info_map = get_user_info() category_map = get_category() user_cnt_iter = read_tsv("data/user_cnt.csv", delimiter=",") user_aid_cnt_iter = next_row(read_tsv("data/user_aid_cnt.csv", delimiter=",")) main()
parser = argparse.ArgumentParser(description='Process some integers.') parser.add_argument('--test', type=int, default=0) parser.add_argument('--mongo', type=int, default=0) parser.add_argument('--sz', type=int, default=None) parser.add_argument('--maxl', type=int, default=1e6) parser.add_argument('--type', type=str, default="ins") parser.add_argument('--sr', type=float, default=0.1) parser.add_argument('--seed', type=int, default=9) parser.add_argument('--date', type=int, default=0) parser.add_argument('--log', type=int, default=1) args = parser.parse_args() if args.mongo: from pymongo import MongoClient import functools32 as functools client = MongoClient('localhost', 27017) db = client.test @functools.lru_cache(maxsize=1000000) def get_ad_info(aid): ad_info = db.ad_info.find_one({"AdID": aid}) return trans_ad_info(ad_info) user_info_map = get_user_info() category_map = get_category() user_cnt_iter = read_tsv("data/user_cnt_%s.csv_sorted" % args.sz, delimiter=",") user_aid_cnt_iter = next_row( read_tsv("data/user_aid_cnt_%s.csv_sorted" % args.sz, delimiter=",")) main()
def main(): if args.dir == None: timestr = time.strftime("%Y%m%d-%H%M%S") directory = os.path.join('experiment/', timestr) else: directory = args.dir if not os.path.exists(directory): os.mkdir(directory) if args.sport: sport = args.sport else: sport = random.randint(1024, 10000) reps = 5 mss = args.mss max_workers = 20 category_filename = os.path.join(directory, 'categories') result_filename = os.path.join(directory, 'results.csv') categories = {1:[], 2:[], 3:[], 4:[], 5:[]} if args.ip: ips = args.ip.split(',') outputs = U.repeat_iw_query(ips=ips, sport=sport, reps=reps, mss=mss) for j, output in enumerate(zip(*outputs)): results, errors, use_error_req = output category, result = U.get_category(results) categories[category].append((ips[j], result)) result_str = ','.join([str(res) for res in results]) error_str = ','.join([str(error) for error in errors]) print('IP Address: {},Initial Windows: {}, Error Number: {}\n'.format(ips[j], result_str, error_str)) else: if args.low == None or args.high == None: raise Exception('Missing arguments to both IP and Low/High range. At least one must be supplied') if args.low >= args.high: raise Exception('Passed in low parameter is greater than or equal to high parameter. --low must be lower than --high') num_ips = args.high - args.low ip_list = U.get_ip_list(amount=num_ips, offset=args.low) result_file = open(result_filename, 'w') result_file.write('IP,Used_error,Results,Errors\n') itr = math.ceil(len(ip_list) / max_workers) pbar = tqdm(total=itr) for i in range(itr): end = min((i + 1) * max_workers, len(ip_list)) ips = ip_list[(i*max_workers):end] outputs = U.repeat_iw_query(ips=ips, sport=sport, reps=reps, mss=mss) for j, output in enumerate(zip(*outputs)): results, errors, use_error_req = output category, result = U.get_category(results) categories[category].append((ips[j], result)) result_str = ','.join([str(res) for res in results]) error_str = ','.join([str(error) for error in errors]) result_file.write('{},{},{},{}\n'.format(ips[j], use_error_req, result_str, error_str)) pbar.update(1) print('Number of IPs: {}'.format(len(ip_list))) print('---------------') category_total = 0 for i in range(1, 6): category_len = len(categories[i]) category_total += category_len print('Category {}: {}'.format(i, category_len)) print('Total: {}'.format(category_total)) results = [result for (ip, result) in categories[1] if result > 0] result_total = 0 print('---------------') for i in range(1, 11): count = results.count(i) result_total += count print('ICW {}: {}'.format(i, count)) print('ICW 11+: {}'.format(len(results) - result_total)) print('Total: {}'.format(len(results))) with open(category_filename, 'wb') as category_file: pickle.dump(categories, category_file) print('Saved categories pickle to "{}"'.format(category_filename))