-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP: Auto-Select via SAM * load data from datastore * send element class to sam server * mag handling * rough sam integration into frontend * use embedding route from backend instead of fetching precomputed embedding * small unrelated bug fix for canceling poll under certain race condition * switch for dynamic vs hardcoded embedding * better error handling and disable fetching of hardcoded embedding * only use user-requested bbox when applying results for better performance * request embedding for actual user position * implement caching and reuse of embedding * temporarily disable most CI checks * restore application.conf setting for slick and swagger; add another comment to explain impact on dev instances * make it work in arbitrary mags * integrate mag into embedding cache * show busy indicator when loading embedding * remove the entire heuristic-based quickselect code * refactor and clean up so that ML and heuristic based quick select are both usable * allow to select AI or not for quick select in UI * fix inverted style * only allow quick-select with SAM on wkorg * make sam select compatible with other viewports * refactor embedding request * fix linting * Revert "temporarily disable most CI checks" This reverts commit 3f28c99. * prefetch embedding as soon as user presses mouse down * use segmentAnythingEnabled instead of isWkorgInstance * update snapshots * also prefetch ORT session * use camel case in infer code * optimize extraction of mask * rename some vars * adapt analytics event * update changelog * update docs * fix some deprecations * don't cache failed embeddings; only support uint8 in ai mode * re-add assertion, disable in conf by default * update snapshot (segmentAnything disabled by default) * don't clamp min coord of bounding boxes to 0 * remove unnecessary V3.max calls * pr feedback * catch error better if wasm cannot be loaded * avoid redundant error toast * further simplication for bbox * add assertion for bbox < 1024**2 * slice cache when adding to it instead of when accessing it * remove time measurement code * align user bbox to mag before using it to ai-select * more bbox alignment (except for geometry) * fix onnxCoord interpretation for yz viewport * fix mag-alignment logic by rewriting the alignWithMag function to provide more strategies * fix usage of wrong cache entries because of zero-volume bounding boxes that led to positive containment checks * fix that QuickSelectGeometry would be invisible when the third dimension's fractional was below 0.5 * extrude bounding boxes by correctly mag-adapted depth * add comments to inference code * prefetch session as soon as quick select tool is activated * allow to cancel quick select with escape while drawing rectangle * fix invisible geometry * clean up console.logs * fix linting * include intensity min/max and element class in byte array sent to sam server * assert min/max intensity is supplied if element class is float or double * fix frontend typecheck * send intensity range to embedding endpoint if layer is not uint8 * backend error messages * use 4 bytes each for min/max of intensity range, not 8 * only show center marker when using old quick-select mode; fix scale of center marker * add comment * send metadata with correct endianness * take layer name into account when caching embedding --------- Co-authored-by: Philipp Otto <[email protected]> Co-authored-by: Philipp Otto <[email protected]> Co-authored-by: Norman Rzepka <[email protected]>
- Loading branch information
1 parent
53e6686
commit 155e94e
Showing
46 changed files
with
1,853 additions
and
1,039 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package models.binary | ||
|
||
import com.scalableminds.util.tools.Fox | ||
import com.scalableminds.webknossos.datastore.rpc.RPC | ||
import com.scalableminds.webknossos.datastore.models.datasource.ElementClass | ||
import utils.WkConf | ||
|
||
import java.nio.{ByteBuffer, ByteOrder} | ||
import javax.inject.Inject | ||
|
||
class WKRemoteSegmentAnythingClient @Inject()(rpc: RPC, conf: WkConf) { | ||
def getEmbedding(imageData: Array[Byte], | ||
elementClass: ElementClass.Value, | ||
intensityMin: Option[Float], | ||
intensityMax: Option[Float]): Fox[Array[Byte]] = { | ||
val metadataLengthInBytes = 1 + 1 + 4 + 4 | ||
val buffer = ByteBuffer.allocate(metadataLengthInBytes + imageData.length) | ||
buffer.put(ElementClass.encodeAsByte(elementClass)) | ||
buffer.put(if (intensityMin.isDefined && intensityMax.isDefined) 1.toByte else 0.toByte) | ||
buffer.order(ByteOrder.LITTLE_ENDIAN).putFloat(intensityMin.getOrElse(0.0f)) | ||
buffer.order(ByteOrder.LITTLE_ENDIAN).putFloat(intensityMax.getOrElse(0.0f)) | ||
val imageWithMetadata = buffer.array() | ||
System.arraycopy(imageData, 0, imageWithMetadata, metadataLengthInBytes, imageData.length) | ||
rpc(s"${conf.SegmentAnything.uri}/predictions/sam_vit_l") | ||
.addQueryString("elementClass" -> elementClass.toString) | ||
.postBytesWithBytesResponse(imageWithMetadata) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.