def loadcenters(filename): f = open(filename) centers = [] #round = lambda x: sorted([int(x), int(x)+1], key=lambda y: abs(y-x))[0] for line in f: info = line.split(" ")[2:] center = info[2] center = center.split(",") center[0] = int(round(float(center[0]))) center[1] = int(round(float(center[1]))) if center[0]<100 or center[1]<100: continue if center[0]>(width-100) or center[1]>(height-100): continue size = [int(i) for i in info[1].split("+")[0].split("x")] if size[0]>350: centers.append(center[::-1]) # WARNING? else: centers.append(center[::-1]) return centers
def load_grand_truth(self, fileAbsPath): # Loads all categories that are available aDict = {} try: print("Loading grand_truth ............... ", fileAbsPath.split()[-2]) with open(os.path.join(fileAbsPath), 'r') as desc: lines = desc.readlines() # Removing any whitespace characters appearing in the lines for line in lines: split_data = line.split(",") if split_data[1] == 'junk': print("Junk") else: label_id, label = split_data[0], split_data[1].strip() #print("loading label_id: {} with character: {}".format(label_id, label)) aDict[label_id] = label aDict = OrderedDict(sorted(aDict.items(), key=lambda t: t[0])) print("FINISH loading grand_truth ............... ", fileAbsPath.split()[-2]) print("Found: .............{} data".format(len(lines))) return aDict, len(lines) except FileNotFoundError as e: print(e) print("Oops! grand truth file not found. Try again...")
def extractFrontsSelfCreatedNoDuplicates(filename, classes, lonOff, latOff): fronts = [[] for x in range(len(classes))] for line in open(filename, 'r'): content = line.split() if(len(content)==0): continue for idx, className in enumerate(classes): if(content[0] == className): latCoords = []#np.zeros((len(content)-1)//2) lonCoords = []#np.zeros((len(content)-1)//2) # basis change such than lat ranges from 180 (bot) to 0 (top) # and lon ranges from 0 left to 360 right lastLat = -1 lastLon = -1 for idx2 in range(1,len(content),2): lat = float(content[idx2][1:-1]) - latOff lon = float(content[idx2+1][:-1]) - lonOff newLat = lat#round(latRes//2-(1/latStep)*(lat))%latRes newLon = lon#round((1/lonStep)*(lon))%lonRes # Only extract a point if it is different from the previous (do not generate duplicates) if(newLat != lastLat or newLon != lastLon): lastLat = newLat lastLon = newLon latCoords.append(lastLat) lonCoords.append(lastLon) fronts[idx].append(np.array(latCoords)) fronts[idx].append(np.array(lonCoords)) return fronts
def read_chosen_config(chosen_file_path): chose_file = open(chosen_file_path, 'r') lines = chose_file.readlines() dictionary = {} for line in lines: line = line.replace("\n","") line = line.split(",") dictionary[line[0]] = line[1] == "1" return dictionary
def read_line_config(): config_file = open(line_mark_path, "r") lines = config_file.readlines() config_dictionary = {} for line in lines: parts = line.split(",") parts[1] = parts[1].replace("\n", "") config_dictionary[parts[0]] = parts[1] == "True" return config_dictionary
def load_world_live(world_id, **kwargs): # Connect to the game print('Logging in...') cur_dir = os.getcwd() res_dir = os.path.abspath(os.path.join(cur_dir, '..', 'res')) if 'credential' in kwargs: credential = kwargs.get('credential') with open(f'{res_dir}\\{credential}') as fp: line = fp.readline() spl = line.split(' ') username = spl[0] password = spl[1] elif 'user' in kwargs and 'pass' in kwargs: username = kwargs.get('user') password = kwargs.get('pass') else: username = '******' password = '******' init_lock = Lock() init_lock.acquire() global wd wd = None @EventHandler.add('init') def on_init(r, init_message): print('Got init') r.send('init2') width = init_message[18] height = init_message[19] global wd wd = np.empty((width, height), dtype=int) world_data = get_world_data(init_message) for x in range(width): for y in range(height): wd[x, y] = world_data[x, y, 0].block_id init_lock.release() temp_client = Client('everybody-edits-su9rn58o40itdbnw69plyw', username, password) # Get the game version from BigDB version = temp_client.bigdb_load('config', 'config')['version'] # Join a room room = temp_client.create_join_room(world_id, f'Everybodyedits{version}', True) room.send('init') init_lock.acquire(timeout=5.0) room.disconnect() return wd
def prepare_lines(self, lines): """ do complicated line stuff :param lines: :return: """ ret = [] for line in lines: ret.append([float(x) for x in line.split(' ')]) return ret
def extractHRFrontsGen(filename, classes, lonOff, latOff): fronts = [[] for _ in range(len(classes))] currentClass = '' for line in open(filename, 'r'): content = line.split() if(len(content)==0): currentClass = '' continue if(content[0] == '48HR'): break # If we encounter a no front class keyword of the format, reset the currentClass and go to next line if(content[0] in ['$$','TROF', 'LOWS', 'HIGHS']): currentClass = '' continue # if we encounter a front class keyword of the format, reset the currentClass and process the line if(content[0] in ["WARM", "COLD", "OCFNT", "STNRY"]): currentClass = '' for idx, className in enumerate(classes): if(content[0] == className): currentClass = className latCoords = np.zeros(len(content)-1) lonCoords = np.zeros(len(content)-1) # HR has no classification in intensity # csb Latitude is in degrees north # csv Longitude is in degrees west for idx2, coord in enumerate(content[1:]): lat = int(coord[:3])/10 - latOff lon = -int(coord[3:])/10 - lonOff latCoords[idx2] = lat#round((latRes)//2-(1/latStep)*(lat))%(latRes) lonCoords[idx2] = lon#round((1/lonStep)*(lon))%(lonRes) fronts[idx].append(latCoords) fronts[idx].append(lonCoords) # Old class continues elif(currentClass == className): latCoords = np.zeros(len(content)+1) lonCoords = np.zeros(len(content)+1) # set start at end of previous line to leave no gaps latCoords[0] = fronts[idx][-2][-1] lonCoords[0] = fronts[idx][-1][-1] # HR has no classification in intensity # csb Latitude is in degrees north # csv Longitude is in degrees west for idx2, coord in enumerate(content): lat = int(coord[:3])/10 - latOff lon = -int(coord[3:])/10 - lonOff latCoords[idx2+1] = lat#round((latRes)//2-(1/latStep)*(lat))%latRes lonCoords[idx2+1] = lon#round((1/lonStep)*(lon))%lonRes fronts[idx].append(latCoords) fronts[idx].append(lonCoords) return fronts
def read_anno_result(anno_path): anno_file = open(anno_path, "r") lines = anno_file.readlines() anno_dictionary = {} for line in lines: parts = line.split(",") contents = [] for i in range(1, len(parts)): if parts[i].isdigit(): parts[i] = int(parts[i]) contents.append(parts[i]) anno_dictionary[parts[0]] = contents print anno_dictionary[parts[0]] return anno_dictionary
def load_roi(filename): f = open(filename, 'r') text = f.read() f.close() kind = None pts = None for line in text.split('\n'): if kind is None: kind = line pts = [] elif line == '': makeROI(kind, pts) kind = None pts = None else: pts.append(tuple(int(i) for i in line.split()))
def load_roi(filename): f = open(filename, 'r') text=f.read() f.close() kind=None pts=None for line in text.split('\n'): if kind is None: kind=line pts=[] elif line=='': makeROI(kind,pts) kind=None pts=None else: pts.append(tuple(int(i) for i in line.split()))
def load_label_file(path): with open(path) as contents: lines = contents.readlines() lanes = [] for line in lines: line = line.replace(" \n", "") coords_str = line.split(" ") coords = [] true_idx = 0 for i in range(int(len(coords_str) / 2)): coords.append((float(coords_str[true_idx]), float(coords_str[true_idx + 1]))) true_idx += 2 lanes.append(coords) return lanes
def generate_roc_curve_from_outputs(processed_data_folder, model_file, splitfile, datafile_pattern): model = load_model(model_file) files = [] with open(splitfile) as f: flag = False for line in f.readlines(): if flag: chunks = line.split('/') world = chunks[1] files.append(processed_data_folder + world + '/' + datafile_pattern) elif 'validation files' in line: flag = True inputs = [] labels = [] for f in files: new_set, labs = get_inputs_from_file(f) inputs = inputs + new_set labels = labels + labs inputs = np.array(inputs) inputs = inputs.reshape(inputs.shape[0], inputs.shape[1], inputs.shape[2], 1) predictions = model.predict_proba(inputs) TPR = [] FPR = [] for i in np.linspace(0, 1, 100): generated_labels = [j >= i for j in predictions] TP = 0 FN = 0 FP = 0 TN = 0 for k in range(len(generated_labels)): if generated_labels[k] and labels[k]: TP += 1 if generated_labels[k] and not labels[k]: FP += 1 if not generated_labels[k] and labels[k]: FN += 1 if not generated_labels[k] and not labels[k]: TN += 1 TPR.append(float(TP) / float(TP + FN)) FPR.append(float(FP) / float(FP + TN)) return ((TPR, FPR, predictions))
def load_list(path, blob_type='rad'): detect_f = open(path, 'r+') paths = [] blobs = [] for line in detect_f: toks = line.split(' ') path = toks[0] blob_dim = 3 _blobs = [] argc = int(toks[1]) if blob_dim == 'rect': blob_dim = 4 for i in range(argc): blob = [] for j in range(blob_dim): blob.append(int(toks[2 + blob_dim * i + j])) _blobs.append(blob) paths.append(path) blobs.append(_blobs) return paths, blobs