def get_snapshot(self): """Process self.camera image into a Snapshot. Returns: snap (snapshot.Snapshot): snapshot generated from self.camera image. """ SRC_CORNERS = np.array(self.projector["SRC_CORNERS"]) DEST_CORNERS = np.array(self.projector["DEST_CORNERS"]) frame = self.get_raw_frame() if frame is not None: cv2.imshow("Tinycam", frame) # TODO: move user input handling out of this method # Handle keypress events key = self.get_key() if key == 'q': sys.exit() if key == 'f': self.toggle_fullscreen() if key == 'c': self.projector["CALIBRATE"] = True if self.projector.get("CALIBRATE"): corners = self.find_corners(frame) if corners is not None: SRC_CORNERS = corners self.projector["SRC_CORNERS"] = corners self.projector["CALIBRATE"] = False self.homography, status = cv2.findHomography(SRC_CORNERS, DEST_CORNERS) image = self.camera_to_projector_space(frame) snap = snapshot.Snapshot(image) return snap
def save(self, f, buffer_size=10, use_pickle=False): '''Save model parameters using io/snapshot. Args: f: file name buffer_size: size (MB) of the IO, default setting is 10MB; Please make sure it is larger than any single parameter object. use_pickle(Boolean): if true, it would use pickle for dumping; otherwise, it would use protobuf for serialization, which uses less space. ''' if use_pickle: params = {} # since SINGA>=1.1.1 (1101) params['SINGA_VERSION'] = __version__ for (name, val) in zip(self.param_names(), self.param_values()): val.to_host() params[name] = tensor.to_numpy(val) if not f.endswith('.pickle'): f = f + '.pickle' with open(f, 'wb') as fd: pickle.dump(params, fd) else: if f.endswith('.bin'): f = f[0:-4] sp = snapshot.Snapshot(f, True, buffer_size) for (name, val) in zip(self.param_names(), self.param_values()): val.to_host() sp.write(name, val)
def get_snapshot(self): """Process self.camera image into a Snapshot. Returns: snap (snapshot.Snapshot): snapshot generated from self.camera image. """ SRC_CORNERS = np.array(self.projector["SRC_CORNERS"]) DEST_CORNERS = np.array(self.projector["DEST_CORNERS"]) frame = self.get_raw_frame() if frame is not None: cv2.imshow("Tinycam", frame) if self.projector.get("CALIBRATE"): corners = self.find_corners(frame) if corners is not None: SRC_CORNERS = corners self.projector["SRC_CORNERS"] = corners self.projector["CALIBRATE"] = False self.homography, status = cv2.findHomography( SRC_CORNERS, DEST_CORNERS) image = self.camera_to_projector_space(frame) snap = snapshot.Snapshot(image) return snap
def load(self, f, buffer_size=10, use_pickle=False): '''Load model parameters using io/snapshot. Please refer to the argument description in save(). ''' if use_pickle: print 'NOTE: If your model was saved using Snapshot, '\ 'then set use_pickle=False for loading it' with open(f, 'rb') as fd: params = pickle.load(fd) for (specs, val) in zip(self.param_specs(), self.param_values()): try: val.copy_from_numpy(params[specs.name]) except AssertionError as err: print 'Error from copying values for param: %s' % specs.name print 'shape of param vs checkpoint', val.shape, params[specs.name].shape raise err else: print 'NOTE: If your model was saved using pickle, '\ 'then set use_pickle=True for loading it' sp = snapshot.Snapshot(f, False, buffer_size) params = sp.read() for (specs, val) in zip(self.param_specs(), self.param_values()): val.copy_data(params[specs.name])
def load(self, f, buffer_size=10, use_pickle=False): '''Load model parameters using io/snapshot. Please refer to the argument description in save(). ''' version = 0 def get_name(name): if version < 1101: idx = name.rfind('/') assert idx > 0, '/ must be in the parameter name' name = name[:idx] + '_' + name[idx + 1:] return name if use_pickle: print('NOTE: If your model was saved using Snapshot, ' 'then set use_pickle=False for loading it') if not os.path.exists(f): # guess the correct path if f.endswith('.pickle'): f = f[0:-7] else: f = f + '.pickle' assert os.path.exists(f), 'file not exists %s w/o .pickle' % f with open(f, 'rb') as fd: params = pickle.load(fd) else: print('NOTE: If your model was saved using pickle, ' 'then set use_pickle=True for loading it') if f.endswith('.bin'): f = f[0:-4] sp = snapshot.Snapshot(f, False, buffer_size) params = sp.read() if 'SINGA_VERSION' in params: version = params['SINGA_VERSION'] for name, val in zip(self.param_names(), self.param_values()): name = get_name(name) if name not in params: print('Param: %s missing in the checkpoint file' % name) continue try: if isinstance(params[name], tensor.Tensor): val.copy_data(params[name]) else: val.copy_from_numpy(params[name]) except AssertionError as err: print('Error from copying values for param: %s' % name) print('shape of param vs checkpoint', val.shape, params[name].shape) raise err
def load(self, f, buffer_size=10, use_pickle=False): '''Load model parameters using io/snapshot. Please refer to the argument description in save(). ''' if use_pickle: print 'NOTE: If your model was saved using Snapshot, '\ 'then set use_pickle=False for loading it' with open(f, 'rb') as fd: params = pickle.load(fd) for (specs, val) in zip(self.param_specs(), self.param_values()): val.copy_from_numpy(params[specs.name]) else: print 'NOTE: If your model was saved using pickle, '\ 'then set use_pickle=True for loading it' sp = snapshot.Snapshot(f, False, buffer_size) params = sp.read() for (specs, val) in zip(self.param_specs(), self.param_values()): val.copy_data(params[specs.name])
def save(self, f, buffer_size=10, use_pickle=False): '''Save model parameters using io/snapshot. Args: f: file name buffer_size: size (MB) of the IO, default setting is 10MB; Please make sure it is larger than any single parameter object. use_pickle(Boolean): if true, it would use pickle for dumping; otherwise, it would use protobuf for serialization, which uses less space. ''' if use_pickle: params = {} for (specs, val) in zip(self.param_specs(), self.param_values()): val.to_host() params[specs.name] = tensor.to_numpy(val) with open(f, 'wb') as fd: pickle.dump(params, fd) else: sp = snapshot.Snapshot(f, True, buffer_size) for (specs, val) in zip(self.param_specs(), self.param_values()): val.to_host() sp.write(specs.name, val)
def getSnapshotId(): snap = snapshot.Snapshot() return snap.getLastId()
open("logs/in" + str(i) + ".txt", 'w') for i in range(n_players) ] player_logs_read = [ open("logs/all" + str(i) + ".txt", 'w') for i in range(n_players) ] game_log = open("logs/game.txt", 'w') for i in range(n_players): players[i].logfile_send = player_logs_send[i] players[i].logfile_read = player_logs_read[i] # maze stores players, food, walls and open space maze = mazes.generate_maze(width, height, 0.1) # Store state in snapshot state = snapshot.Snapshot() state.width = width state.height = height state.content = maze state.names = [ player_bin[7:min(14, len(player_bin) - 3)] for player_bin in player_bins ] state.scores = [0 for x in range(n_players)] state.status = ['' for x in range(n_players)] # TODO: make beginning coordinates symmetric instead of random state.snakes = [[mazes.get_empty_cell(maze, width, height, str(x))] for x in range(n_players)] state.food = []
def __init__(self, snapshot_id): self.db_conn = db.DatabaseConnection("openauditDB") self.db_conn = self.db_conn.getConn() self.snap = snapshot.Snapshot() self.snap.id = snapshot_id
# Set the caffe device if args.cpu: caffe.set_mode_cpu() else: # TODO: Set_device(1) runs the framework on gpu 0, fix this. 0 seems to # be the "default" GPU, don't know why it is always the nb 1 though caffe.set_device(args.gpu) caffe.set_mode_gpu() # Read in the configuration file tlMsg = transferLearning_pb2.TransferLearning() protoUtils.readFromPrototxt(tlMsg, args.config) configDir = os.path.abspath(os.path.dirname(args.config)) # Initialize the snapshot to save snapshot = snapshot.Snapshot() # If we have to restore something snapshotToRestore = None doRestore = False if args.resume: snapshotToRestore = snapshot.copyFrom(args.resume) snapshotToRestore.verify() doRestore = True logger.info('We will restore the training from %s', args.resume) # Command-line out dir takes priority, if not provided, we use the one in # the config file, if still not provided, we use the current directory outDir = args.out_dir if outDir is None and tlMsg.HasField(F_OUT_DIR): outDir = os.path.join(configDir, tlMsg.out_dir)
def _load_snapshot_file(self): self.snapshot = snapshot.Snapshot(self.file_name) self._init_snapshot_memory()
import sys import logging as log import snapshot import verifier import reporter log.basicConfig(stream=sys.stdout, level=log.INFO) if __name__ == '__main__': snap = snapshot.Snapshot() snapshot_id = snap.getUnverifiedSnapshot() log.info("Running verifier for snapshot id %s", snapshot_id) log.info("Isolation...") v1 = verifier.IsolationVerifier() noncompliant_hosts, missing_instances = v1.run(snapshot_id) r1 = reporter.IsolationReporter(snapshot_id) r1.saveData(noncompliant_hosts, missing_instances) log.info("SecurityGroups...") v2 = verifier.SecurityGroupsVerifier() inconsistent_ports = v2.run(snapshot_id) r2 = reporter.SecurityGroupsReporter(snapshot_id) r2.saveData(inconsistent_ports) log.info("Routes...") v3 = verifier.RoutesVerifier() inconsistent_routes = v3.run(snapshot_id) r3 = reporter.RoutesReporter(snapshot_id) r3.saveData(inconsistent_routes)