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

Enable AI Neuron segmentation #7357

Merged
merged 6 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
6 changes: 5 additions & 1 deletion app/controllers/JobsController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import models.binary.DatasetDAO
import models.job._
import models.organization.OrganizationDAO
import models.binary.DataStoreDAO
import models.user.MultiUserDAO
import oxalis.security.{WkEnv, WkSilhouetteEnvironment}
import oxalis.telemetry.SlackNotificationService
import play.api.i18n.Messages
Expand All @@ -25,6 +26,7 @@ class JobsController @Inject()(jobDAO: JobDAO,
workerService: WorkerService,
workerDAO: WorkerDAO,
wkconf: WkConf,
multiUserDAO: MultiUserDAO,
wkSilhouetteEnvironment: WkSilhouetteEnvironment,
slackNotificationService: SlackNotificationService,
organizationDAO: OrganizationDAO,
Expand Down Expand Up @@ -170,6 +172,8 @@ class JobsController @Inject()(jobDAO: JobDAO,
dataSet <- datasetDAO.findOneByNameAndOrganization(dataSetName, organization._id) ?~> Messages(
"dataset.notFound",
dataSetName) ~> NOT_FOUND
multiUser <- multiUserDAO.findOne(request.identity._multiUser)
_ <- Fox.runIf(!multiUser.isSuperUser)(jobService.assertBoundingBoxLimits(bbox, None))
command = JobCommand.infer_neurons
commandArgs = Json.obj(
"organization_name" -> organizationName,
Expand Down Expand Up @@ -199,7 +203,7 @@ class JobsController @Inject()(jobDAO: JobDAO,
dataSet <- datasetDAO.findOneByNameAndOrganizationName(dataSetName, organizationName) ?~> Messages(
"dataset.notFound",
dataSetName) ~> NOT_FOUND
_ <- jobService.assertTiffExportBoundingBoxLimits(bbox, mag)
_ <- jobService.assertBoundingBoxLimits(bbox, mag)
userAuthToken <- wkSilhouetteEnvironment.combinedAuthenticatorService.findOrCreateToken(
request.identity.loginInfo)
command = JobCommand.export_tiff
Expand Down
10 changes: 5 additions & 5 deletions app/models/job/Job.scala
Original file line number Diff line number Diff line change
Expand Up @@ -433,13 +433,13 @@ class JobService @Inject()(wkConf: WkConf,
_ <- workerDAO.findOneByDataStore(dataStoreName)
} yield ()

def assertTiffExportBoundingBoxLimits(boundingBox: String, mag: Option[String]): Fox[Unit] =
def assertBoundingBoxLimits(boundingBox: String, mag: Option[String]): Fox[Unit] =
for {
parsedBoundingBox <- BoundingBox.fromLiteral(boundingBox).toFox ?~> "job.export.tiff.invalidBoundingBox"
parsedMag <- Vec3Int.fromMagLiteral(mag.getOrElse("1-1-1"), allowScalar = true) ?~> "job.export.tiff.invalidMag"
parsedBoundingBox <- BoundingBox.fromLiteral(boundingBox).toFox ?~> "job.invalidBoundingBox"
parsedMag <- Vec3Int.fromMagLiteral(mag.getOrElse("1-1-1"), allowScalar = true) ?~> "job.invalidMag"
boundingBoxInMag = parsedBoundingBox / parsedMag
_ <- bool2Fox(boundingBoxInMag.volume <= wkConf.Features.exportTiffMaxVolumeMVx * 1024 * 1024) ?~> "job.export.tiff.volumeExceeded"
_ <- bool2Fox(boundingBoxInMag.size.maxDim <= wkConf.Features.exportTiffMaxEdgeLengthVx) ?~> "job.export.tiff.edgeLengthExceeded"
_ <- bool2Fox(boundingBoxInMag.volume <= wkConf.Features.exportTiffMaxVolumeMVx * 1024 * 1024) ?~> "job.volumeExceeded"
_ <- bool2Fox(boundingBoxInMag.size.maxDim <= wkConf.Features.exportTiffMaxEdgeLengthVx) ?~> "job.edgeLengthExceeded"
} yield ()

}
8 changes: 4 additions & 4 deletions conf/messages
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,10 @@ job.couldNotRunApplyMergerMode = Failed to start job to apply merger mode annota
job.disabled = Long-running jobs are not enabled for this WEBKNOSSOS instance.
job.worker.notFound = Could not find this worker in the database.
job.export.fileNotFound = Exported file not found. The link may be expired.
job.export.tiff.invalidBoundingBox = The selected bounding box could not be parsed, must be x,y,z,width,height,depth
job.export.tiff.invalidMag = The selected mag could not be parsed, must be x-y-z
job.export.tiff.volumeExceeded = The volume of the selected bounding box is too large.
job.export.tiff.edgeLengthExceeded = An edge length of the selected bounding box is too large.
job.invalidBoundingBox = The selected bounding box could not be parsed, must be x,y,z,width,height,depth
job.invalidMag = The selected mag could not be parsed, must be x-y-z
job.volumeExceeded = The volume of the selected bounding box is too large.
job.edgeLengthExceeded = An edge length of the selected bounding box is too large.
job.inferNuclei.notAllowed.organization = Currently nuclei inferral is only allowed for datasets of your own organization.
job.inferNeurons.notAllowed.organization = Currently neuron inferral is only allowed for datasets of your own organization.
job.meshFile.notAllowed.organization = Calculating mesh files is only allowed for datasets of your own organization.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function getExportLayerInfos(
};
}

function isBoundingBoxExportable(boundingBox: BoundingBoxType, mag: Vector3) {
export function isBoundingBoxExportable(boundingBox: BoundingBoxType, mag: Vector3) {
const shape = computeShapeFromBoundingBox(boundingBox);
const volume =
Math.ceil(shape[0] / mag[0]) * Math.ceil(shape[1] / mag[1]) * Math.ceil(shape[2] / mag[2]);
Expand All @@ -132,7 +132,7 @@ function isBoundingBoxExportable(boundingBox: BoundingBoxType, mag: Vector3) {
type="error"
message={`An edge length of the selected bounding box (${shape.join(
", ",
)}) is too large. Tiff export is only supported for boxes with no edge length over ${
)}) is too large. Tiff export is only supported for boxes with edges smaller than ${
features().exportTiffMaxEdgeLengthVx
} vx.`}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,11 @@ export function getAISegmentationMenu(
icon: <SettingOutlined />,
label: "AI Segmentation",
children: [
{
key: "ai-nuclei-segmentation",
label: "AI Nuclei Segmentation",
onClick: () => Store.dispatch(setAINucleiSegmentationModalVisibilityAction(true)),
},
// {
// key: "ai-nuclei-segmentation",
// label: "AI Nuclei Segmentation",
// onClick: () => Store.dispatch(setAINucleiSegmentationModalVisibilityAction(true)),
// },
{
key: "ai-neuron-segmentation",
label: "AI Neuron Segmentation",
Expand Down Expand Up @@ -674,7 +674,7 @@ class TracingActionsView extends React.PureComponent<Props, State> {
});
}

if (features().jobsEnabled && activeUser != null && activeUser.isSuperUser) {
if (features().jobsEnabled) {
const [AISegmentationMenu, AISegmentationModals] = getAISegmentationMenu(
this.props.isAINucleiSegmentationModalOpen,
this.props.isAINeuronSegmentationModalOpen,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import { clamp, computeArrayFromBoundingBox, rgbToHex } from "libs/utils";
import { getBaseSegmentationName } from "oxalis/view/right-border-tabs/segments_tab/segments_view_helper";
import { V3 } from "libs/mjs";
import { ResolutionInfo } from "oxalis/model/helpers/resolution_info";
import { isBoundingBoxExportable } from "../action-bar/download_modal_view";
import features from "features";

const { ThinSpace } = Unicode;
const enum JobNames {
Expand Down Expand Up @@ -222,8 +224,12 @@ function BoundingBoxSelectionFormItem({
isBoundingBoxConfigurable,
userBoundingBoxes,
onChangeSelectedBoundingBox,
value,
value: selectedBoundingBoxId,
}: BoundingBoxSelectionProps): JSX.Element {
const dataset = useSelector((state: OxalisState) => state.dataset);
const colorLayer = getColorLayers(dataset)[0];
const mag1 = colorLayer.resolutions[0];

return (
<div style={isBoundingBoxConfigurable ? {} : { display: "none" }}>
<p>
Expand All @@ -240,13 +246,32 @@ function BoundingBoxSelectionFormItem({
required: isBoundingBoxConfigurable,
message: "Please select the bounding box for which the inferral should be computed.",
},
{
required: true,
validator: (_rule, value) => {
const selectedBoundingBox = userBoundingBoxes.find((bbox) => bbox.id === value);
if (selectedBoundingBox) {
const { isExportable, alerts: _ } = isBoundingBoxExportable(
selectedBoundingBox.boundingBox,
mag1,
);
if (isExportable) return Promise.resolve();
}
return Promise.reject();
},
message: `The volume of the selected bounding box is too large. The AI neuron segmentation trail is only supported for up to ${
hotzenklotz marked this conversation as resolved.
Show resolved Hide resolved
features().exportTiffMaxVolumeMVx
} Megavoxels. Additionally, no bounding box edge should be longer than ${
features().exportTiffMaxEdgeLengthVx
}vx.`,
},
]}
hidden={!isBoundingBoxConfigurable}
>
<BoundingBoxSelection
userBoundingBoxes={userBoundingBoxes}
setSelectedBoundingBoxId={onChangeSelectedBoundingBox}
value={value}
value={selectedBoundingBoxId}
/>
</Form.Item>
</div>
Expand Down