def get_next(): file_path = utils.poll(real_path('processed_votes')) lines_processed = utils.lines(real_path('processed_votes')) lines_processing = utils.lines(real_path('processing_votes')) to_process = PROCESSING_BUFFER_SIZE - lines_processed - lines_processing process(to_process) return file_path
def i3conf_actions(): return lines( "# Actions", bindsym("Mod1+q", "kill"), bindsym("Mod1+Shift+c", "reload"), bindsym("Mod1+Shift+r", "restart"), bindsym("Mod1+Shift+e", "i3-nagbar -t warning", "-m 'Do you really want to exit i3?'", "-b 'Yes, exit i3' 'i3-msg exit'"), "")
def i3conf_workspaces(): return lines("# Workspaces", bindsym_exec("Mod1+Control+l", "i3-msg workspace next"), bindsym_exec("Mod1+Control+h", "i3-msg workspace prev"), bindsym_exec("Mod1+Shift+Control+l", "i3-msg move container to workspace next"), bindsym_exec("Mod1+Shift+Control+h", "i3-msg move container to workspace prev"), bindsym_exec("Mod1+Control+j", "i3-msg workspace back_and_forth"), bindsym_exec("Mod1+Shift+Control+j", "i3-msg move container to workspace" "back_and_forth"), bindsym("Mod1+Control+k", "scratchpad show"), bindsym("Mod1+Shift+Control+k", "move scratchpad"), bindsym_exec("Mod1+space", "i3-msg workspace $(lsws | menu →)"), bindsym_exec("Mod1+Shift+space", "i3-msg move container to workspace", "$(lsws | menu →)"), "workspace 0 output VGA1", "")
def i3conf_actions(): return lines("# Actions", bindsym("Mod1+q", "kill"), bindsym("Mod1+Shift+c", "reload"), bindsym("Mod1+Shift+r", "restart"), bindsym("Mod1+Shift+e", "i3-nagbar -t warning", "-m 'Do you really want to exit i3?'", "-b 'Yes, exit i3' 'i3-msg exit'"), "")
def i3conf_volume(): return lines( "# Volume", bindsym_exec("XF86AudioRaiseVolume", "amixer -q set Master 5%+ unmute"), bindsym_exec("XF86AudioLowerVolume", "amixer -q set Master 5%- unmute"), bindsym_exec("XF86AudioMute", "amixer -q set Master toggle"), bindsym_exec("XF86AudioMicMute", "amixer -q set Capture toggle"), "")
def read_annotation(annotation_path): data = [] for line in lines(annotation_path): cells = line.split(";") if cells[0] == "Filename": continue image_path, klass = os.path.join(os.path.dirname(annotation_path), cells[0]), int(cells[-1]) data.append((image_path, klass)) return data
def i3conf_theme(): return lines( "# Theme", "font xft:{} 7".format(font), row("client.focused", color.main, color.bg, color.main, color.bg), row("client.focused_inactive", color.smooth, color.bg, color.fg, color.bg), row("client.unfocused", color.smooth, color.bg, color.fg, color.bg), row("client.urgent", color.smooth, color.bg, color.fg, color.alert), row("client.placeholder", color.smooth, color.bg, color.fg, color.bg), "new_window pixel 1", "new_float pixel 1" "")
def main(fname): print(fname) file_path = "{}.txt".format(fname) data = lines(file_path) outgoing_graph, incoming_graph = build_graphs(data) dead_ends_ordered = find_dead_ends(outgoing_graph) v = page_rank_with_dead_ends(outgoing_graph, incoming_graph, dead_ends_ordered) output_page_rank(v, "10" if len(outgoing_graph) == 10000 else "800")
def i3conf_commads(): return lines( "# Commands", bindsym_exec("Print", "scrot '%Y-%m-%d-%T_$wx$h.png'", "-e 'mv $f ~/images/'"), bindsym("Mod1+Return", "exec sakura"), bindsym_exec("XF86MonBrightnessUp", "luce +20"), bindsym_exec("XF86MonBrightnessDown", "luce -20"), "", bindsym_exec("XF86ScreenSaver", "~/bin/lock"), "", bindsym_exec("Mod1+d", "PATH=$PATH:~/bin", "dmenu_path | menu", quotes("-"), "| zsh &"), bindsym_exec("Mod1+semicolon", "PATH=$PATH:~/bin", "stest -flx ~/bin |", "menu", quotes("-"), "| zsh &"), "")
def main(fname): file_path = "{}.txt".format(fname) data = lines(file_path) graph = build_graph(data) dead_ends = find_dead_ends(graph) # print(dead_ends) dead_ends = np.hstack(dead_ends) print(len(dead_ends), "dead ends") output(sorted(dead_ends), "10" if len(graph) == 10000 else "800")
def i3conf_volume(): return lines("# Volume", bindsym_exec("XF86AudioRaiseVolume", "amixer -q set Master 5%+ unmute"), bindsym_exec("XF86AudioLowerVolume", "amixer -q set Master 5%- unmute"), bindsym_exec("XF86AudioMute", "amixer -q set Master toggle"), bindsym_exec("XF86AudioMicMute", "amixer -q set Capture toggle"), "")
def i3conf_movement(): return lines("# Movement", bindsym("Mod1+h", "focus left"), bindsym("Mod1+j", "focus down"), bindsym("Mod1+k", "focus up"), bindsym("Mod1+l", "focus right"), "", bindsym("Mod4+h", "focus output left"), bindsym("Mod4+j", "focus output down"), bindsym("Mod4+k", "focus output up"), bindsym("Mod4+l", "focus output right"), "", bindsym("Mod4+Shift+h", "move workspace to output left"), bindsym("Mod4+Shift+j", "move workspace to output down"), bindsym("Mod4+Shift+k", "move workspace to output up"), bindsym("Mod4+Shift+l", "move workspace to output right"), "", bindsym("Mod1+Shift+h", "move left"), bindsym("Mod1+Shift+j", "move down"), bindsym("Mod1+Shift+k", "move up"), bindsym("Mod1+Shift+l", "move right"), "")
def i3conf_windowing(): return lines( "# Windowing", bindsym("Mod1+o", "split h"), bindsym("Mod1+v", "split v"), "floating_modifier Mod1", bindsym("Mod1+t", "floating toggle"), bindsym("Mod1+f", "fullscreen toggle"), bindsym("Mod1+s", "layout stacking"), bindsym("Mod1+w", "layout tabbed"), bindsym("Mod1+e", "layout toggle split"), bindsym("Mod1+p", "focus parent"), bindsym("Mod1+c", "focus child"), mode("resize", bindsym("h", "resize shrink width 10 px or 10 ppt"), bindsym("j", "resize grow height 10 px or 10 ppt"), bindsym("k", "resize shrink height 10 px or 10 ppt"), bindsym("l", "resize grow width 10 px or 10 ppt"), bindsym_mode("Return", "default"), bindsym_mode("Escape", "default"), ""), bindsym_mode("Mod1+r", "resize"), "")
def i3conf_theme(): return lines("# Theme", "font xft:{} 7".format(font), row("client.focused", color.main, color.bg, color.main, color.bg), row("client.focused_inactive", color.smooth, color.bg, color.fg, color.bg), row("client.unfocused", color.smooth, color.bg, color.fg, color.bg), row("client.urgent", color.smooth, color.bg, color.fg, color.alert), row("client.placeholder", color.smooth, color.bg, color.fg, color.bg), "new_window pixel 1", "new_float pixel 1" "")
def __init__(self, data_root): # Dimensionality of image features img_dim = 4096 self._model = Sequential() self._model.add(Reshape(input_shape=(img_dim,), target_shape=(img_dim,))) # Load the precomputed VGG features print("Loading VGG features...") pretrained_vgg_model_fpath = pjoin(data_root, 'coco', 'vgg_feats.mat') features_struct = scipy.io.loadmat(pretrained_vgg_model_fpath) self._vgg_features = features_struct['feats'] image_ids = lines(pjoin(data_root, 'coco_vgg_IDMap.txt')) print ("Done.") self._id_map = {} for ids in image_ids: id_split = ids.split() self._id_map[id_split[0]] = int(id_split[1])
def i3conf_workspaces(): return lines( "# Workspaces", bindsym_exec("Mod1+Control+l", "i3-msg workspace next"), bindsym_exec("Mod1+Control+h", "i3-msg workspace prev"), bindsym_exec("Mod1+Shift+Control+l", "i3-msg move container to workspace next"), bindsym_exec("Mod1+Shift+Control+h", "i3-msg move container to workspace prev"), bindsym_exec("Mod1+Control+j", "i3-msg workspace back_and_forth"), bindsym_exec("Mod1+Shift+Control+j", "i3-msg move container to workspace" "back_and_forth"), bindsym("Mod1+Control+k", "scratchpad show"), bindsym("Mod1+Shift+Control+k", "move scratchpad"), bindsym_exec("Mod1+space", "i3-msg workspace $(lsws | menu →)"), bindsym_exec("Mod1+Shift+space", "i3-msg move container to workspace", "$(lsws | menu →)"), "workspace 0 output VGA1", "")
def i3conf_bar(): return lines( "# Bar", block( "bar", # row("status_command", "i3status"), row("output", "LVDS1"), row("status_command", "i3status"), row("position", "bottom"), "font xft:{} 7".format(font), row("separator_symbol", quotes(" · ")), block("colors", row("background", color.bg), row("statusline", color.fg), row("separator", color.main), row("focused_workspace", color.main, color.bg, color.main), row("active_workspace", color.bg, color.bg, "#5f676a"), row("inactive_workspace", color.bg, color.bg, color.fg), row("urgent_workspace", color.alert, color.bg, color.alert), "")), "")
def i3conf_commads(): return lines("# Commands", bindsym_exec("Print", "scrot '%Y-%m-%d-%T_$wx$h.png'", "-e 'mv $f ~/images/'"), bindsym("Mod1+Return", "exec sakura"), bindsym_exec("XF86MonBrightnessUp", "luce +20"), bindsym_exec("XF86MonBrightnessDown", "luce -20"), "", bindsym_exec("XF86ScreenSaver", "~/bin/lock"), "", bindsym_exec("Mod1+d", "PATH=$PATH:~/bin", "dmenu_path | menu", quotes("-"), "| zsh &"), bindsym_exec("Mod1+semicolon", "PATH=$PATH:~/bin", "stest -flx ~/bin |", "menu", quotes("-"), "| zsh &"), "")
def i3conf_windowing(): return lines("# Windowing", bindsym("Mod1+o", "split h"), bindsym("Mod1+v", "split v"), "floating_modifier Mod1", bindsym("Mod1+t", "floating toggle"), bindsym("Mod1+f", "fullscreen toggle"), bindsym("Mod1+s", "layout stacking"), bindsym("Mod1+w", "layout tabbed"), bindsym("Mod1+e", "layout toggle split"), bindsym("Mod1+p", "focus parent"), bindsym("Mod1+c", "focus child"), mode("resize", bindsym("h", "resize shrink width 10 px or 10 ppt"), bindsym("j", "resize grow height 10 px or 10 ppt"), bindsym("k", "resize shrink height 10 px or 10 ppt"), bindsym("l", "resize grow width 10 px or 10 ppt"), bindsym_mode("Return", "default"), bindsym_mode("Escape", "default"), ""), bindsym_mode("Mod1+r", "resize"), "")
def i3conf_bar(): return lines("# Bar", block("bar", # row("status_command", "i3status"), row("output", "LVDS1"), row("status_command", "i3status"), row("position", "bottom"), "font xft:{} 7".format(font), row("separator_symbol", quotes(" · ")), block("colors", row("background", color.bg), row("statusline", color.fg), row("separator", color.main), row("focused_workspace", color.main, color.bg, color.main), row("active_workspace", color.bg, color.bg, "#5f676a"), row("inactive_workspace", color.bg, color.bg, color.fg), row("urgent_workspace", color.alert, color.bg, color.alert), "") ), "")
import sys import os import utils import fileinput from language import * print sys.argv #print os.listdir(sys.argv[1]) mCount = 0 mMultiFlag = False clang = CLan() for line in utils.lines(fileinput.input(sys.argv[1])): print line if mMultiFlag is True: if clang.isMultiCommentEnd(line): print 'multi comment end' mMultiFlag = False continue else: print 'multiflag' continue if clang.isSingleComment(line): print 'single comment' continue if clang.isMultiCommentBegin(line):
def main(): parser = argparse.ArgumentParser() parser.add_argument('-model', type=str, required=True, help="JSON dump of saved model structure.") parser.add_argument('-weights', type=str, required=True, help="Saved weights (checkpoint).") parser.add_argument('-results', type=str, required=True, help="File where to write the results.") parser.add_argument('-results_json', type=str, required=True, help="File where to dump the evaluation results in " "JSON format, so that the official VQA toolkit " "can read it.") parser.add_argument('-dataroot', type=str, default='/data/vqa') args = parser.parse_args() root = args.dataroot model = model_from_json(open(args.model).read()) model.load_weights(args.weights) model.compile(loss='categorical_crossentropy', optimizer='rmsprop') questions_val = lines(pjoin(root, 'Preprocessed', 'questions_val2014.txt')) questions_id = lines( pjoin(root, 'Preprocessed', 'questions_id_val2014.txt')) answers_val = lines(pjoin(root, 'Preprocessed', 'answers_val2014_all.txt')) images_val = lines(pjoin(root, 'Preprocessed', 'images_val2014_all.txt')) vgg_model_path = pjoin(root, 'coco', 'vgg_feats.mat') print('Model compiled, weights loaded...') # Load the encoder which converts answers to IDs, saved in the same # folder as the rest of the dumps. exp_root = args.weights[:args.weights.rfind('/')] labelencoder = joblib.load(pjoin(exp_root, 'labelencoder.pkl')) features_struct = scipy.io.loadmat(vgg_model_path) VGGfeatures = features_struct['feats'] print('loaded vgg features') image_ids = lines(pjoin(root, 'coco_vgg_IDMap.txt')) img_map = {} for ids in image_ids: id_split = ids.split() img_map[id_split[0]] = int(id_split[1]) nlp = English() print('loaded word2vec features') nb_classes = 1000 y_predict_text = [] # TODO(andrei): Configure this via args. batchSize = 512 stuff = batchify(batchSize, questions_val, answers_val, images_val) with click.progressbar(stuff) as pbar: for (qu_batch, an_batch, im_batch) in pbar: # TODO(Bernhard): make this choose the right preprocessing and right model, # for now you have to plug it in manually #X_q_batch = get_questions_matrix_sum(qu_batch, nlp) # for sum up model X_q_batch = get_questions_tensor_timeseries(qu_batch, nlp, 20) # for LSTM model if 'language_only' in args.model: y_predict = model.predict_classes([X_q_batch], verbose=0) else: X_i_batch = get_images_matrix(im_batch, img_map, VGGfeatures) y_predict = model.predict_classes([X_q_batch, X_i_batch], verbose=0) # TODO(Bernhard): verify that predict_classes sets dropout to 0 y_predict_text.extend(labelencoder.inverse_transform(y_predict)) correct_val = 0.0 total = 0 f1 = open(args.results, 'w') print("Will dump resulting answers in JSON format to file: [{0}]".format( args.results_json)) result_file_json = open(args.results_json, 'w') result_file_json.write("[") all_preds = list( zip(y_predict_text, answers_val, questions_val, questions_id, images_val)) for idx, (prediction, truth, question, question_id, image) in enumerate(all_preds): temp_count = 0 for _truth in truth.split(';'): if prediction == _truth: temp_count += 1 if temp_count > 2: correct_val += 1 else: correct_val += float(temp_count) / 3 total += 1 f1.write(question) f1.write('\n') f1.write(image) f1.write('\n') f1.write(prediction) f1.write('\n') f1.write(truth) f1.write('\n') f1.write('\n') # Note: Double-braces are escaped braces in Python format strings. result_file_json.write( '{{"answer": "{0}", "question_id": {1}}}{2}\n'.format( prediction, question_id, ',' if idx < len(all_preds) - 1 else '')) result_file_json.write("]\n") f1.write('Final Accuracy is ' + str(correct_val / total)) f1.close() # TODO(andrei): Re-add this, so we are neat about keeping track of all our # results. # f1 = open('../results/overall_results.txt', 'a') # f1.write(args.weights + '\n') # f1.write(str(correct_val / total) + '\n') # f1.close() print('Final Accuracy on the validation set is', correct_val / total)
def __init__(self, set_path, mode, preprocess=default_preprocessing, augment=True, only_front_camera=False, split="manual", return_image_paths=False): self.data = [] self.preprocess = preprocess self.augment = augment self.only_front_camera = only_front_camera self.return_image_paths = return_image_paths print("Data:", self.data) print("Augment:", self.augment) print("OFC:", self.only_front_camera) print("RIP:", self.return_image_paths) print("---------------------") if mode not in ("train", "validation", "test", "visualize"): raise ValueError("Invalid mode.") self.mode = mode origin_path = os.path.join(set_path, "origin.txt") for line in lines(origin_path): self.origin = torch.Tensor(tuple(map(float, line.split(" ")))) #camera_paths = [ # os.path.join("front", "center"), # os.path.join("front", "left"), # os.path.join("front", "right"), # os.path.join("back", "center"), # os.path.join("back", "left"), #os.path.join("back", "right") #] #for camera_path in camera_paths: # poses_path = os.path.join(mode_path, camera_path, "poses.txt")''' if mode == "visualize": mode_path = os.path.join(set_path, "front", "center") poses_path = os.path.join(mode_path, "poses.txt") for filename, x, y, qw, qx, qy, qz in read_table( poses_path, types=(str, float, float, float, float, float, float), delimiter=" "): _, _, theta = euler_from_quaternion((qw, qx, qy, qz)) assert theta >= -np.pi and theta <= np.pi ''' Normalization ''' # This makes x and y independent of the origin x, y, _ = torch.Tensor([x, y, 0]) + self.origin x, y, theta = PerceptionCarDataset.normalize(x, y, theta) '''''' pose = (x, y, theta) image_path = os.path.join(mode_path, filename) # image_path = os.path.join(set_path, filename) self.data.append((image_path, pose)) else: poses_path = os.path.join(set_path, "{}.{}.txt".format(mode, split)) for *filenames, x, y, qw, qx, qy, qz in read_table( poses_path, types=(str, str, str, str, str, str, float, float, float, float, float, float), delimiter=" "): _, _, theta = euler_from_quaternion((qw, qx, qy, qz)) assert theta >= -np.pi and theta <= np.pi ''' Normalization ''' # This makes x and y independent of the origin x, y, _ = torch.Tensor([x, y, 0]) + self.origin x, y, theta = PerceptionCarDataset.normalize(x, y, theta) '''''' pose = (x, y, np.cos(theta), np.sin(theta)) image_paths = map(lambda fn: os.path.join(set_path, fn), filenames) #image_paths = filenames if self.only_front_camera: self.data.append((next(image_paths), pose)) else: self.data.append((*image_paths, pose)) self.size = len(self.data)