Skip to content

Commit

Permalink
apply PR feedback #2
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-wer committed Apr 9, 2019
1 parent 7dcae93 commit 9589321
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
6 changes: 2 additions & 4 deletions frontend/javascripts/libs/floodfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ export default function(options: FloodfillOptions) {
let flooded = [];
const visits = {};

// $FlowFixMe Flow doesn't allow to use an array as the key
const visited = key => visits[key] === true;
const visited = key => visits[key.toString()] === true;

const markAsVisited = key => {
// $FlowFixMe Flow doesn't allow to use an array as the key
visits[key] = true;
visits[key.toString()] = true;
};

const member = getArgs => getter(getArgs[0], getArgs[1], getArgs[2]);
Expand Down
15 changes: 9 additions & 6 deletions frontend/javascripts/oxalis/model/sagas/volumetracing_saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
type Vector3,
type ContourMode,
ContourModeEnum,
OrthoViews,
type OrthoView,
type VolumeTool,
VolumeToolEnum,
Expand Down Expand Up @@ -348,10 +349,12 @@ function* inferSegmentInViewport(action: InferSegmentationInViewportAction): Sag
const tensorArray = new Float32Array(new Uint8Array(cuboidData)).map(
el => (el - mean) / stdDev,
);
// When interpreting the 3d data slice as a 2d slice, the x and y axis are flipped only on the YZ plane
const isXYflipped = activeViewport === OrthoViews.PLANE_YZ;

return useWebworker
? workerPredict(useGPU, tensorArray.buffer, inputExtent)
: mainThreadPredict(useGPU, tf, tensorArray.buffer, inputExtent);
? workerPredict(useGPU, tensorArray.buffer, inputExtent, isXYflipped)
: mainThreadPredict(useGPU, tf, tensorArray.buffer, inputExtent, isXYflipped);
};

function* currentPositionUpdater(): Saga<void> {
Expand Down Expand Up @@ -414,11 +417,11 @@ function* inferSegmentInViewport(action: InferSegmentationInViewportAction): Sag
const seed = clickPosition;
const seedPrediction = yield* call(getter, ...seed);
if (seedPrediction) {
// The floodfill will run until aborted
floodfill({ getter, seed, onFlood });

// Keep updating the current position
yield* call(currentPositionUpdater);
yield* fork(currentPositionUpdater);

// The floodfill will run until aborted or exhausted
yield* call(floodfill, { getter, seed, onFlood });
} else {
Toast.warning("Click position is classified as border, please click inside a segment instead.");
}
Expand Down
6 changes: 5 additions & 1 deletion frontend/javascripts/oxalis/workers/tensorflow.impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default async function predict(
tf: Object,
buffer: ArrayBuffer,
inputExtent: number,
isXYflipped: boolean,
) {
if (useGPU) {
tf.setBackend("webgl");
Expand All @@ -21,7 +22,10 @@ export default async function predict(
}

let tensor = tf.tensor4d(tensorArray, [1, inputExtent, inputExtent, 1]);
tensor = tf.transpose(tensor, [0, 2, 1, 3]);
// The tensorflow model expects a flipped x/y-axis
if (!isXYflipped) {
tensor = tf.transpose(tensor, [0, 2, 1, 3]);
}

const model = segmentationModel;
const inferredTensor = model.predict(tensor);
Expand Down
4 changes: 2 additions & 2 deletions frontend/javascripts/oxalis/workers/tensorflow.worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ if (typeof OffscreenCanvas !== "undefined") {

const tf = require("@tensorflow/tfjs");

function predictWrapper(useGPU, buffer: ArrayBuffer, inputExtent: number) {
return predict(useGPU, tf, buffer, inputExtent);
function predictWrapper(useGPU, buffer: ArrayBuffer, inputExtent: number, isXYflipped: boolean) {
return predict(useGPU, tf, buffer, inputExtent, isXYflipped);
}

export default expose<typeof predictWrapper>(predictWrapper);

0 comments on commit 9589321

Please sign in to comment.