def test_single(self, file_in, save_to=None, save_prob=False, unload=True): if isinstance(file_in, Dataset): ds = file_in else: print(file_in) ds = Dataset(file_in) probs = self.predict_probability(ds.points_and_features) new_classes = np.argmax(probs, axis=2) if save_to: Dataset.Save(save_to, ds.points_and_features, ds.names, ds.labels, new_classes[0], probs[0] if save_prob else None) cm = confusion_matrix(ds.labels, new_classes[0], range(self.num_classes)) self.eval_history.add_history_step(cm, self._train_points_seen, 0) if unload: ds.unload() return np.count_nonzero(ds.labels == new_classes[0]) / self.num_points
def main(args): inlist = args.inList threshold = args.threshold train_size = args.trainSize arch = importlib.import_module(args.archFile).arch if args.archFile else arch lr = args.learningRate normalize_vals = args.normalize == 1 with open(inlist, "rb") as f: _ = f.readline() # remove header rest = f.readlines() datasets = [] all_ds = [] for line in rest: line = line.decode('utf-8') linespl = line.split(",") dataset_path = os.path.join(os.path.dirname(inlist), linespl[0]) if float(linespl[1]) < threshold: datasets.append(dataset_path) all_ds.append(dataset_path) np.random.shuffle(datasets) datasets_th = [] for idx, dataset in enumerate(datasets): print("Loading dataset %s of %s (%s)" % (idx+1, len(datasets), os.path.basename(dataset))) ds = Dataset(dataset, load=False, normalize=normalize_vals) datasets_th.append(ds) print("%s datasets loaded." % len(datasets_th)) sys.stdout.flush() inst = AlsNetContainer(num_feat=160, num_classes=6, num_points=50000, output_base=args.outDir, score_sample=10, arch=arch, learning_rate=lr, dropout=0.55, loss_fn=simple_loss if args.lossFn == "simple" else fp_high_loss) if args.continueModel is not None: inst.load_model(args.continueModel) logg = Logger(outfile=os.path.join(args.outDir, 'alsNet-log.html'), inst=inst, training_files=datasets_th) for j in range(args.multiTrain): for i in range((len(datasets_th)//train_size)-1): if i > 0: test_ds = datasets_th[i*train_size] print(test_ds.file) inst.test_single(test_ds, save_to=os.path.join(args.outDir, os.path.basename(test_ds.file).replace(".la", "_test.la")), save_prob=False) print("Training datasets %s to %s (%s total)" % (i*train_size, min((i+1)*train_size, len(datasets_th)), len(datasets_th))) inst.fit(datasets_th[i*train_size:min((i+1)*train_size, len(datasets_th))], new_session=False) logg.save() inst.save_model(os.path.join(args.outDir, 'models', 'model_%d_%d' % (j, i), 'alsNet.ckpt'))
def fit_file(self, filenames_in, new_session=True, **kwargs): if new_session or self._graph is None: self.close_session() self._train_points_seen = 0 self._graph = tf.Graph() with self._graph.as_default(): self._build_graph() self._session = tf.Session(graph=self._graph, config=self._config) with self._session.as_default() as sess: sess.run(self._init_op) for filename in filenames_in: ds = Dataset(filename) self.fit_one_epoch(ds.points_and_features, ds.labels) return self
def main(args): arch = importlib.import_module(args.arch).arch normalize = args.normalize model = AlsNetContainer(num_feat=160, num_classes=6, num_points=50000, output_base=args.outDir, arch=arch1, arch2=arch2) logging.info("Loading pretrained model %s" % args.model) model.load_model(args.model) datasets = [] if not os.path.exists(args.outDir): os.makedirs(args.outDir) for filepattern in args.inFiles: for file in glob.glob(filepattern): datasets.append(Dataset(file, load=False, normalize=normalize)) logging.info("File %s loaded" % file) total_acc = 0 total_batch = 0 for idx, dataset in enumerate(datasets): logging.info("Loading dataset %d / %d (%s)" % (idx, len(datasets), dataset.filename)) acc = model.test_single(dataset, save_to=os.path.join( args.outDir, os.path.basename(dataset.file).replace( ".la", "_test.la")), save_prob=True, unload=False) logging.info("Current test accuracy: %.2f%%" % (acc * 100.)) meanxy = np.mean(dataset._xyz, axis=1)[0:2] with open(os.path.join(args.outDir, 'result.csv'), 'a') as out_stat_file: out_stat_file.write("%s, %.3f, %.3f, %.4f\n" % (dataset.file, meanxy[0], meanxy[1], acc)) dataset.unload() total_acc += acc total_batch += 1 logging.info("Current avg test accuracy: %.2f%%" % ((total_acc / total_batch) * 100.)) sys.stdout.flush()