Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Robodummy #57

Draft
wants to merge 45 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
5b8c573
robo user first commit
Pranjal-sopho Jun 11, 2019
04e3fd9
Merge pull request #1 from ilastik/master
Pranjal-sopho Jun 11, 2019
73e4c47
some changes
Pranjal-sopho Jun 11, 2019
2dec996
Merge remote-tracking branch 'origin/master' into robodummy
Pranjal-sopho Jun 11, 2019
3d66cbc
structural changes
Pranjal-sopho Jun 12, 2019
7bf8f81
some structural changes
Pranjal-sopho Jun 13, 2019
d157d9d
deleted unnecessary files
Pranjal-sopho Jun 13, 2019
39fb936
changed tiling to generic+ apply black
Pranjal-sopho Jun 13, 2019
52d0114
switched to n5 for better mem mang.
Pranjal-sopho Jun 17, 2019
83316c2
incorporated suggestions
Pranjal-sopho Jun 18, 2019
8814e98
added test folder
Pranjal-sopho Jun 18, 2019
eb19bb3
indexing now generic and loss configurable
Pranjal-sopho Jun 21, 2019
8220b95
added basic tensorboard logger
Pranjal-sopho Jun 21, 2019
35af962
made changes acc to previous review
Pranjal-sopho Jun 25, 2019
ae97dbd
tiling now completely generic+other modifications
Pranjal-sopho Jun 27, 2019
3b8b7d7
bug fixed in tile_image + other changes
Pranjal-sopho Jul 2, 2019
84d61cb
tests now running
Pranjal-sopho Jul 5, 2019
28640d6
Merge pull request #2 from ilastik/master
Pranjal-sopho Jul 5, 2019
997c4eb
more tensorboard logging
Pranjal-sopho Jul 5, 2019
d355deb
Merge branch 'master' into obodummy
Pranjal-sopho Jul 5, 2019
a9cfecd
tensorboard errors fixed
Pranjal-sopho Jul 8, 2019
fd1eb97
new strategy added
Pranjal-sopho Jul 10, 2019
cba7191
sparse annotation strategies added
Pranjal-sopho Jul 11, 2019
f265faf
video labelling strategies added
Pranjal-sopho Jul 17, 2019
fcce3f2
class annotator added
Pranjal-sopho Jul 19, 2019
4daa134
all bugs fixed
Pranjal-sopho Jul 22, 2019
6be7a82
apply black
Pranjal-sopho Jul 22, 2019
f38692a
Merge pull request #3 from ilastik/master
Pranjal-sopho Jul 22, 2019
27c4f43
new commit
Pranjal-sopho Jul 22, 2019
d1a1cdc
added gitignore
Pranjal-sopho Jul 22, 2019
064c27c
Merge branch 'master' into robodummy
Pranjal-sopho Jul 22, 2019
4c6d9cb
testing..
Pranjal-sopho Jul 23, 2019
3940c55
Update environemnt file to include MrRobot deps
m-novikov Jul 23, 2019
5da186d
Add __init__ and __main__
m-novikov Jul 23, 2019
f45d619
Make __main__ work
m-novikov Jul 23, 2019
3db31e9
Fix confusion_matrix nans
m-novikov Jul 23, 2019
79a77da
Fixes to strategies
m-novikov Jul 23, 2019
6bd9d7e
Fix unstopabble predictions of inferno trainer
m-novikov Jul 23, 2019
055d08f
Add train_for method to tiktorch server
m-novikov Jul 23, 2019
3eec9c8
Use train_for in mr_robot
m-novikov Jul 23, 2019
8e907e3
training problems fixed (temporarily)
Pranjal-sopho Jul 24, 2019
c6ddc1d
training problems fixed (temporarily)
Pranjal-sopho Jul 24, 2019
617a4df
training problems fixed (temporarily)
Pranjal-sopho Jul 25, 2019
39a674d
updating with code used for result prep
Pranjal-sopho Oct 2, 2019
9050f93
strategy params passed generalized and hardcodings for done for resul…
Pranjal-sopho Nov 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
switched to n5 for better mem mang.
  • Loading branch information
Pranjal-sopho committed Jun 17, 2019
commit 52d011437643c9f586758542d1ecd217816bcdb5
65 changes: 41 additions & 24 deletions mr_robot/mr_robot.py
Original file line number Diff line number Diff line change
@@ -4,8 +4,10 @@
import torch.nn as nn
import torch.nn.functional as f
from sklearn.metrics import mean_squared_error
from model import DUNet2D
#from model import DUNet2D
import h5py
import z5py
from z5py.converter import convert_from_h5
from scipy.ndimage import convolve
from torch.autograd import Variable
from collections import OrderedDict
@@ -17,17 +19,21 @@
from utils import *

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe sort the import statements a little don't mix import... and from... too much

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

patch_size = 16

img_dim = 32

class MrRobot:
def __init__(self):
# start the server
self.new_server = TikTorchServer()


def load_data(self):
with h5py.File("train.hdf", "r") as f:
x = np.array(f.get("volumes/labels/neuron_ids"))
y = np.array(f.get("volumes/raw"))
self.f = z5py.File('train.n5')
return self.f
"""
#with h5py.File("train.hdf", "r") as f:
# x = np.array(f.get("volumes/labels/neuron_ids"))
# y = np.array(f.get("volumes/raw"))

self.labels = []
self.ip = []
@@ -40,6 +46,7 @@ def load_data(self):
self.ip = NDArray(np.asarray(self.ip)[:, :, 0:patch_size, 0:patch_size])
print("data loaded")
return (ip, labels)
"""

def load_model(self):
# load the model
@@ -60,10 +67,12 @@ def resume(self):
print("training resumed")

def predict(self):
self.op = new_server.forward(self.ip)
self.ip = np.expand_dims(self.f['volume'][0,0:img_dim, 0:img_dim], axis = 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, variable names need some polishing. They should be descriptive and have a clear scope.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of taking the first slice [0, ...] and then expanding the resulting array, you should simplify to take a slice right away:
[0:1, ...]

#self.label = np.expand_dims(self.f['volumes/labels/neuron_ids'][0,0:img_dim,0:img_dim], axis=0)
self.op = self.new_server.forward(self.ip)
self.op = op.result().as_numpy()
print("prediction run")
return (self.op, self.labels)
return self.op

def add(self, row, column):
self.ip = self.ip.as_numpy()[
@@ -79,32 +88,38 @@ def add(self, row, column):
def dense_annotate(self, x, y, label, image):
raise NotImplementedError

def terminate():
new_server.shutdown()
def terminate(self):
self.new_server.shutdown()


class BaseStrategy:
def __init__():
raise NotImplementedError
def __init__(self, file, op):
self.f = file
self.op = op

# compute loss for a given patch
def base_loss(self, patch, label):
label = label[0][0]
patch = patch[0][0]
result = mean_squared_error(label, patch) # CHECK THIS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the criterion should be configurable

return result


class Strategy1(BaseStrategy):
def __init__(self, op, labels):
super().__init__()
pred_idx = tile_image2D(op[0, 0].shape, 16)
actual_idx = tile_image2D(labels[0, 0].shape, 16)
w, h, self.row, self.column = 32, 32, -1, -1
def __init__(self, file, op):
super().__init__(file,op)

def run(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer the robot class to perform the 'run', not the strategy. The strategy should effectively implement a sampling strategy. I see this analog to the pytorch sampler.
We might even be able to use the pytorch dataset and the pytorch dataloader for our purposes (and then implement our strategy as a 'Sampler'

idx = tile_image(self.op.shape, patch_size)
label = np.expand_dims(self.f['volumes/labels/neuron_ids'][0,0:img_dim,0:img_dim], axis=0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same indexing as in predict method

#idx = tile_image(label.shape, patch_size)
w, h, self.row, self.column = img_dim, img_dim, -1, -1
error = 1e7
for i in range(len(pred_patches)):
for i in range(len(idx)):
# print(pred_patches[i].shape, actual_patches[i].shape)
curr_loss = self.loss(
op[0, 0, pred_idx[i][0] : pred_idx[i][1], pred_idx[i][2] : pred_idx[i][3]],
labels[0, 0, actual_idx[i][0] : actual_idx[i][1], actual_idx[i][2] : actual_idx[i][3]],
curr_loss = super().base_loss(
self.op[idx[i][0]: idx[i][1], idx[i][2]:idx[i][3], idx[i][4] : idx[i][5], idx[i][6] : idx[i][7]],
labels[idx[i][0]: idx[i][1], idx[i][2]:idx[i][3], idx[i][4] : idx[i][5], idx[i][6] : idx[i][7]],
)
print(curr_loss)
if error > curr_loss:
@@ -128,18 +143,20 @@ def __init__():


if __name__ == "__main__":

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the following code should be inside of MrRobot. Currently you mirror parts of the tiktorch api in MrRobot (methods: resume, predict, add). This is fine for convenience, etc, but in it's core MrRobot should implement the way of running a 'user simulation'

robo = MrRobot()
robo.load_data()
file = robo.load_data()
robo.load_model()
robo.resume() # resume training

# run prediction
op, label = robo.predict()
op = robo.predict()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I think algorithm should be read as follows:

# Step 1. Intialization
robo = MrRobot('/home/user/config.yaml')  # Here robot loads all required data
robo.use_strategy(StrategyRandom())
# or even
robo = MrRobot('/home/user/config.yaml', StrategyRandom)

# Step 2. Start
robo.start()  # Start tiktorch server

# Step 3. Prediction loop
while robo.should_stop():
      robo.predict()

# def robo.predict
# 1. labels? = self.strategy.get_next_patch(<relevant data>)
# 2. self.update_training(labels, ...)

# Step 4. Termination
robo.terminate()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I'd vote for

robo = MrRobot('/home/user/config.yaml', StrategyRandom)

metric = Strategy1(op, label)
metric = Strategy1(file, op)
metric.run()
row, column = metric.get_patch()
robo.add(row, column)

# shut down server
robo.terminate()