-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from Leengit/select_tiles
Version 2.0.0
- Loading branch information
Showing
15 changed files
with
1,185 additions
and
5,072 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,173 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "25408cb3-b6d6-4244-9346-6f3b3166cdb6", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# install histomics_stream\n", | ||
"!pip install -e /tf/notebooks/histomics_stream\n", | ||
"\n", | ||
"# add to system path\n", | ||
"import sys\n", | ||
"\n", | ||
"sys.path.append(\"/tf/notebooks/histomics_stream/\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "d1ecc019-0935-4d07-a245-f61ca1836675", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import copy\n", | ||
"import histomics_stream as hs\n", | ||
"\n", | ||
"# import tensorflow as tf\n", | ||
"\n", | ||
"print(\"Configuring with histomics_stream\")\n", | ||
"\n", | ||
"# Create a study and insert study-wide information\n", | ||
"my_study0 = {\"version\": \"version-1\"}\n", | ||
"my_study0[\"number_pixel_rows_for_tile\"] = 256\n", | ||
"my_study0[\"number_pixel_columns_for_tile\"] = 256\n", | ||
"my_slides = my_study0[\"slides\"] = {}\n", | ||
"\n", | ||
"# Add a slide to the study, including slide-wide information with it.\n", | ||
"my_slide0 = my_slides[\"Slide_0\"] = {}\n", | ||
"my_slide0[\"filename\"] = \"/tf/notebooks/histomics_stream/example/TCGA-BH-A0BZ-01Z-00-DX1.45EB3E93-A871-49C6-9EAE-90D98AE01913.svs\"\n", | ||
"my_slide0[\"slide_name\"] = \"TCGA-BH-A0BZ-01Z-00-DX1\"\n", | ||
"my_slide0[\"slide_group\"] = \"TCGA-BH-A0BZ\"\n", | ||
"my_slide0[\"number_pixel_rows_for_chunk\"] = 2048\n", | ||
"my_slide0[\"number_pixel_columns_for_chunk\"] = 2048\n", | ||
"\n", | ||
"# For each slide, find the appropriate resolution given the desired_magnification and\n", | ||
"# magnification_tolerance. In this example, we use the same parameters for each slide,\n", | ||
"# but this is not required generally.\n", | ||
"find_resolution_for_slide = hs.configure.FindResolutionForSlide(\n", | ||
" my_study0, desired_magnification=20, magnification_tolerance=0.02\n", | ||
")\n", | ||
"for slide in my_study0[\"slides\"].values():\n", | ||
" find_resolution_for_slide(slide)\n", | ||
"print(\"================================================================\")\n", | ||
"print(f\"my_study0 = {my_study0}\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "af6100da-943c-4e56-bf6d-d711169daedb", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# We are going to demonstrate several approaches to choosing tiles. Each approach will\n", | ||
"# start with its own copy of the my_study0 that we have built so far.\n", | ||
"\n", | ||
"# Demonstrate TilesByGridAndMask without a mask\n", | ||
"my_study_tiles_by_grid = copy.deepcopy(my_study0)\n", | ||
"tiles_by_grid = hs.configure.TilesByGridAndMask(\n", | ||
" my_study_tiles_by_grid,\n", | ||
" number_pixel_overlap_rows_for_tile=32,\n", | ||
" number_pixel_overlap_columns_for_tile=32,\n", | ||
" randomly_select=100,\n", | ||
")\n", | ||
"# We could apply this to a subset of the slides, but we will apply it to all slides in\n", | ||
"# this example.\n", | ||
"for slide in my_study_tiles_by_grid[\"slides\"].values():\n", | ||
" tiles_by_grid(slide)\n", | ||
"print(\"================================================================\")\n", | ||
"print(\"Finished with TilesByGrid\")\n", | ||
"print(f\"my_study_tiles_by_grid = {my_study_tiles_by_grid}\")\n", | ||
"\n", | ||
"# Demonstrate TilesByGridAndMask with a mask\n", | ||
"my_study_tiles_by_grid_and_mask = copy.deepcopy(my_study0)\n", | ||
"tiles_by_grid_and_mask = hs.configure.TilesByGridAndMask(\n", | ||
" my_study_tiles_by_grid_and_mask,\n", | ||
" number_pixel_overlap_rows_for_tile=0,\n", | ||
" number_pixel_overlap_columns_for_tile=0,\n", | ||
" mask_filename=\"/tf/notebooks/histomics_stream/example/TCGA-BH-A0BZ-01Z-00-DX1.45EB3E93-A871-49C6-9EAE-90D98AE01913-mask.png\",\n", | ||
" randomly_select=100,\n", | ||
")\n", | ||
"# We could apply this to a subset of the slides, but we will apply it to all slides in\n", | ||
"# this example.\n", | ||
"for slide in my_study_tiles_by_grid_and_mask[\"slides\"].values():\n", | ||
" tiles_by_grid_and_mask(slide)\n", | ||
"print(\"================================================================\")\n", | ||
"print(\"Finished with TilesByGridAndMask\")\n", | ||
"print(f\"my_study_tiles_by_grid_and_mask = {my_study_tiles_by_grid_and_mask}\")\n", | ||
"\n", | ||
"# Demonstrate TilesByList\n", | ||
"my_study_tiles_by_list = copy.deepcopy(my_study0)\n", | ||
"tiles_by_list = hs.configure.TilesByList(\n", | ||
" my_study_tiles_by_list,\n", | ||
" randomly_select=5,\n", | ||
" tiles_dictionary=my_study_tiles_by_grid[\"slides\"][\"Slide_0\"][\"tiles\"],\n", | ||
")\n", | ||
"# We could apply this to a subset of the slides, but we will apply it to all slides in\n", | ||
"# this example.\n", | ||
"for slide in my_study_tiles_by_list[\"slides\"].values():\n", | ||
" tiles_by_list(slide)\n", | ||
"print(\"================================================================\")\n", | ||
"print(\"Finished with TilesByList\")\n", | ||
"print(f\"my_study_tiles_by_list = {my_study_tiles_by_list}\")\n", | ||
"\n", | ||
"# Demonstrate TilesRandomly\n", | ||
"my_study_tiles_randomly = copy.deepcopy(my_study0)\n", | ||
"tiles_randomly = hs.configure.TilesRandomly(my_study_tiles_randomly, randomly_select=3)\n", | ||
"# We could apply this to a subset of the slides, but we will apply it to all slides in\n", | ||
"# this example.\n", | ||
"for slide in my_study_tiles_randomly[\"slides\"].values():\n", | ||
" tiles_randomly(slide)\n", | ||
"print(\"================================================================\")\n", | ||
"print(\"Finished with TilesRandomly\")\n", | ||
"print(f\"my_study_tiles_randomly = {my_study_tiles_randomly}\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "238948be-b2aa-4558-9c1a-d7dbd7b42cea", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# We choose one of the above examples for further processing.\n", | ||
"my_study_of_tiles = my_study_tiles_by_grid\n", | ||
"\n", | ||
"print(\"Creating a tensorflow Dataset with histomics_stream\")\n", | ||
"\n", | ||
"create_tensorflow_dataset = hs.tensorflow.CreateTensorFlowDataset()\n", | ||
"tiles = create_tensorflow_dataset(my_study_of_tiles)\n", | ||
"print(\"Finished with CreateTensorFlowDataset\")\n", | ||
"\n", | ||
"print(\"================================================================\")\n", | ||
"print(tiles)\n", | ||
"# print(\"================================================================\")\n", | ||
"# tf.print(tiles)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.0" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Oops, something went wrong.