def _make_tuples(self, key): X = Stacks().load(key) voxel = (VoxelSize() & key).fetch1['vx', 'vy', 'vz'] b = RankDegenerateBernoulliProcess(voxel, quadratic_channels=key['quadratic_components'], linear_channels=key['linear_components'], common_channels=key['common_components'] ) cells = (CellLocations() & key).fetch1['cells'] b.fit(X, cells, maxiter=100) key.update(b.parameters) key['train_cross_entropy'] = b.cross_entropy(X, cells) key['train_auc_weighted'] = b.auc(X, cells, average='weighted') key['train_auc'] = b.auc(X, cells, average='macro') self.insert1(key)
self.cells = np.asarray(fid['cells']) if 'cells' in fid else None self.P = np.asarray(fid['P']) if 'P' in fid else np.nan * np.empty(X.shape[:3]) def save(self, stackfile): mode = 'r+' if os.path.exists(stackfile) else 'w' with h5py.File(stackfile, mode) as fid: fid.create_dataset('stack', self.stack.shape, dtype=float, data=self.stack) fid.create_dataset('P', self.P.shape, dtype=float, data=self.P) if self.cells is not None: fid.create_dataset('cells', self.cells.shape, dtype=int, data=self.cells) if __name__ == "__main__": # s = Stack('data/smaller.hdf5', preprocessor=lambda x: preprocess(x).mean(axis=-1).squeeze()) # b = FullBernoulliProcess((9, 9, 7), quadratic_channels=3, linear_channels=3) # s = Stack('data/sanity.hdf5', preprocessor=lambda x: x.mean(axis=-1).squeeze()) # s_test = Stack('data/sanity_test.hdf5', preprocessor=lambda x: x.mean(axis=-1).squeeze()) # b = RankDegenerateBernoulliProcess( (3,3,3), quadratic_channels=3, linear_channels=3, common_channels=3) s = Stack('data/smaller.hdf5', preprocessor=lambda x: histeq(unsharp_masking(medianfilter(center(x.squeeze()))), 500).mean( axis=-1)) b = RankDegenerateBernoulliProcess((11, 11, 9), quadratic_channels=40, linear_channels=40, common_channels=20) # s = Stack('data/2015-08-25_12-49-41_2015-08-25_13-02-18.h5', # preprocessor=lambda x: histeq(unsharp_masking(medianfilter(center(x.squeeze()))),500).mean(axis=-1)) # b = RankDegenerateBernoulliProcess((19, 19, 17), quadratic_channels=40, linear_channels=40, common_channels=20) b.fit(s.X, s.cells, maxiter=50) b.visualize(s.X, s.cells)