Skip to content

Commit

Permalink
refactor: updated reporting results
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-grim committed Oct 15, 2024
1 parent cfdce67 commit a75e11c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/deep_neurographs/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ def run(self, fragments_pointer):
# Finish
self.report("Final Graph...")
self.report_graph()
self.report("\n")

t, unit = util.time_writer(time() - t0)
self.report(f"Total Runtime: {round(t, 4)} {unit}\n")
Expand Down Expand Up @@ -231,12 +230,17 @@ def build_graph(self, fragments_pointer):
# Save valid labels and current graph
swcs_path = os.path.join(self.output_dir, "processed-swcs.zip")
labels_path = os.path.join(self.output_dir, "valid_labels.txt")
self.graph.to_zipped_swcs(swcs_path)
n_saved = self.graph.to_zipped_swcs(swcs_path)
self.graph.save_labels(labels_path)
self.report(f"# SWCs Saved: {n_saved}")

# Report runtime
t, unit = util.time_writer(time() - t0)
self.report(f"Module Runtime: {round(t, 4)} {unit}")

# Report graph overview
self.report("\nInitial Graph...")
self.report_graph()
self.report(f"Module Runtime: {round(t, 4)} {unit}\n")

def generate_proposals(self, radius=None):
"""
Expand Down Expand Up @@ -410,7 +414,7 @@ def report_graph(self):
self.report(f"# Connected Components: {n_components}")
self.report(f"# Nodes: {n_nodes}")
self.report(f"# Edges: {n_edges}")
self.report(f"Memory Consumption: {usage} GBs")
self.report(f"Memory Consumption: {usage} GBs\n")


class InferenceEngine:
Expand Down Expand Up @@ -571,9 +575,9 @@ def get_batch_dataset(self, neurograph, batch):
...
"""
t0 = time()
#t0 = time()
features = self.feature_generator.run(neurograph, batch, self.radius)
print("Feature Generation:", time() - t0)
#print("Feature Generation:", time() - t0)
computation_graph = batch["graph"] if type(batch) is dict else None
dataset = ml_util.init_dataset(
neurograph,
Expand Down
3 changes: 3 additions & 0 deletions src/deep_neurographs/neurograph.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,10 +955,13 @@ def component_path_length(self, root):
# --- write graph to swcs ---
def to_zipped_swcs(self, zip_path, color=None, min_size=100):
with zipfile.ZipFile(zip_path, "w") as zip_writer:
cnt = 0
for nodes in nx.connected_components(self):
root = util.sample_once(nodes)
if self.component_path_length(root) > min_size:
self.to_zipped_swc(zip_writer, nodes, color)
cnt += 1
return cnt

def to_zipped_swc(self, zip_writer, nodes, color):
with StringIO() as text_buffer:
Expand Down

0 comments on commit a75e11c

Please sign in to comment.