-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6bf0975
Showing
15 changed files
with
7,213 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Skinet (Segmentation of the Kidney through a Neural nETwork) Project | ||
|
||
MIT License | ||
|
||
Copyright (c) 2020 Skinet Team | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,23 @@ | ||
Mask R-CNN | ||
|
||
The MIT License (MIT) | ||
|
||
Copyright (c) 2017 Matterport, Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
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,12 @@ | ||
# SKINET (Segmentation of the KIdney through a Neural nETwork) Project | ||
|
||
SKINET Project is meant to perform a segmentation of a kidney's biopsy or a nephrectomy and recognize the different histological structures. By doing that, it is possible to analyze kidneys more precisely and get a better understanding of their behaviors. | ||
|
||
The project's code is based on [Matterport's Mask R-CNN](https://github.com/matterport/Mask_RCNN) and [Navidyou's repository](https://github.com/navidyou/Mask-RCNN-implementation-for-cell-nucleus-detection-executable-on-google-colab-). | ||
|
||
This project is a collaboration between a Nephrology team from [Dijon Burgundy Teaching Hospital](https://www.chu-dijon.fr/), [LEAD Laboratory](http://leadserv.u-bourgogne.fr/en/), and a student from [ESIREM](https://esirem.u-bourgogne.fr/), all located in Dijon, Burgundy, France. | ||
|
||
## Inference tool | ||
Last : [![Open Inference Tool In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/SkinetTeam/Skinet/blob/main/Skinet_Inference_Tool.ipynb) | ||
|
||
v1.0 : [![Open Inference Tool In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/SkinetTeam/Skinet/blob/v1.0/Skinet_Inference_Tool.ipynb) |
Large diffs are not rendered by default.
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,141 @@ | ||
""" | ||
Skinet (Segmentation of the Kidney through a Neural nETwork) Project | ||
Common display/math methods | ||
Copyright (c) 2021 Skinet Team | ||
Licensed under the MIT License (see LICENSE for details) | ||
Written by Adrien JAUGEY | ||
""" | ||
from datetime import datetime | ||
import numpy as np | ||
|
||
|
||
def progressBar(value, maxValue, prefix="", suffix="", forceNewLine=False, size=20, full='█', cursor='▒', | ||
empty='░'): | ||
""" | ||
Prints a progress bar | ||
Based on https://stackoverflow.com/questions/6169217/replace-console-output-in-python | ||
:param value: the current progress value | ||
:param maxValue: the maximum value that could be given | ||
:param prefix: text to display before the progress bar | ||
:param suffix: text to display after the progress bar | ||
:param forceNewLine: False by default, if True a new line will be created even if not at the end | ||
:param size: size of the bar itself | ||
:param full: the character to use for the completed part of the bar | ||
:param cursor: the character to use for the current position | ||
:param empty: the character to use for the empty part of the bar | ||
:return: None | ||
""" | ||
percent = float(value) / maxValue | ||
nbFullChar = int(percent * size) | ||
bar = full * nbFullChar + (cursor if percent > 0 and nbFullChar < size else "") | ||
emptyBar = empty * (size - len(bar)) | ||
print(f'\r{prefix} {bar}{emptyBar} {percent: 6.2%} {suffix}', | ||
end='\n' if value == maxValue or forceNewLine else "", flush=True) | ||
|
||
|
||
def progressText(value, maxValue, onlyRaw=False, onlyPercent=False): | ||
if onlyRaw and onlyPercent: | ||
return None | ||
elif onlyRaw: | ||
return f"({value}/{maxValue})" | ||
else: | ||
percent = float(value) / maxValue | ||
if onlyPercent: | ||
return f"({percent:06.2%})" | ||
else: | ||
return f"({value}/{maxValue} | {percent:06.2%})" | ||
|
||
|
||
def formatTime(seconds: int, minutes: int = 0, hours: int = 0): | ||
""" | ||
Returns a string representing the given time | ||
:param seconds: number of seconds | ||
:param minutes: if given, number of minutes adding to seconds | ||
:param hours: if given, number of hours adding to seconds | ||
:return: formated time as string of "hh:mm:ss" format | ||
""" | ||
seconds += minutes * 60 + hours * 3600 | ||
seconds = int(seconds) | ||
h = seconds // 3600 | ||
m = (seconds % 3600) // 60 | ||
s = seconds % 60 | ||
hText = f"{h:02d}:" if h != 0 else "" | ||
mText = f"{m:02d}:" if h + m != 0 else "" | ||
sText = f"{s:02d}" if h + m != 0 else f"{s:02d}s" | ||
return f"{hText}{mText}{sText}" | ||
|
||
|
||
def formatDate(date: datetime = None, dateOnly=False, timeOnly=False): | ||
""" | ||
Returns date as string | ||
:param date: datetime.datetime object to use specific date, current date and time by default | ||
:param dateOnly: if True, will only display the date, not the time | ||
:param timeOnly: if True, will only display the time, not the date | ||
:return: formatted date as string | ||
""" | ||
if date is None: | ||
date = datetime.now() | ||
else: | ||
assert type(date) is datetime, "Provide date as datetime.datetime object" | ||
dateFormat = '%Y-%m-%d' | ||
timeFormat = '%H-%M-%S' | ||
if dateOnly and timeOnly: | ||
outputFormat = "" | ||
elif dateOnly: | ||
outputFormat = dateFormat | ||
elif timeOnly: | ||
outputFormat = timeFormat | ||
else: | ||
outputFormat = f"{dateFormat}_{timeFormat}" | ||
return date.strftime(outputFormat) | ||
|
||
|
||
def format_number(num, maxLength=None): | ||
""" | ||
Formats a number using a metric prefix such as K (Kilo), M (Mega)... up to Y (Yotta) | ||
:param num: the number to format | ||
:param maxLength: maximum length of the formatted number, will reduce number of decimals from 2 to 0 depending on | ||
the length but will at least return abs(num / 1000^N) followed by the metric prefix for 1000^N. | ||
:return: the formatted number with up to 2 decimal digits | ||
""" | ||
# https://stackoverflow.com/questions/579310/formatting-long-numbers-as-strings-in-python | ||
suffixes = ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'] | ||
magnitude = 0 | ||
isInt = np.issubdtype(type(num), np.integer) | ||
while abs(num) >= 1000 and magnitude < len(suffixes) - 1: | ||
magnitude += 1 | ||
num /= 1000.0 | ||
|
||
if magnitude == 0 and isInt: | ||
return str(int(num)) | ||
|
||
if maxLength is not None: | ||
possibleText = [f"{num:.2f}{suffixes[magnitude]}", | ||
f"{num:.1f}{suffixes[magnitude]}", | ||
f"{num:.0f}{suffixes[magnitude]}"] | ||
for text in possibleText: | ||
if len(text) <= maxLength: | ||
return text | ||
return possibleText[-1] | ||
return f"{num:.1f}{suffixes[magnitude]}" | ||
|
||
|
||
def combination(setSize, combinationSize): | ||
""" | ||
Computes the number of k-combinations in a set | ||
Source : https://python.jpvweb.com/python/mesrecettespython/doku.php?id=combinaisons | ||
:param setSize: number of elements in the set | ||
:param combinationSize: number of elements in a combination | ||
:return: number of k-combinations | ||
""" | ||
if combinationSize > setSize // 2: | ||
combinationSize = setSize - combinationSize | ||
x = 1 | ||
y = 1 | ||
i = setSize - combinationSize + 1 | ||
while i <= setSize: | ||
x = (x * i) // y | ||
y += 1 | ||
i += 1 | ||
return x |
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,25 @@ | ||
name: Skinet | ||
channels: | ||
- defaults | ||
dependencies: | ||
- python=3.7 | ||
- pip: | ||
- tensorflow-gpu==1.15.5 | ||
- tensorboard==1.15 | ||
- keras==2.3.1 | ||
- h5py==2.10.0 | ||
- jupyter | ||
- matplotlib | ||
- numpy==1.18.3 | ||
- opencv-python==4.2.0.34 | ||
- imgaug==0.4.0 | ||
- ipython | ||
- jsonschema | ||
- html5lib | ||
- imageio==2.8.0 | ||
- imagesize==1.2.0 | ||
- pillow==7.1.1 | ||
- scikit-image==0.15.0 | ||
- scipy==1.1.0 | ||
|
||
|
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,78 @@ | ||
""" | ||
Skinet (Segmentation of the Kidney through a Neural nETwork) Project | ||
Copyright (c) 2021 Skinet Team | ||
Licensed under the MIT License (see LICENSE for details) | ||
Written by Adrien JAUGEY | ||
""" | ||
import tensorflow as tf | ||
|
||
version = tf.__version__ | ||
TF_MAJOR, TF_MINOR, TF_PATCH = [int(v) for v in version.split('.')][:3] | ||
|
||
|
||
def get_version(): | ||
return TF_MAJOR, TF_MINOR, TF_PATCH | ||
|
||
|
||
############################################################ | ||
# Arguments rewrite | ||
############################################################ | ||
def crop_and_resize_v1(image, boxes, box_indices, crop_size, method, extrapolation_value, name): | ||
return tf.image.crop_and_resize(image, boxes, box_ind=box_indices, crop_size=crop_size, method=method, | ||
extrapolation_value=extrapolation_value, name=name) | ||
|
||
|
||
def crop_and_resize_v2(image, boxes, box_indices, crop_size, method, extrapolation_value, name): | ||
return tf.image.crop_and_resize(image, boxes, box_indices=box_indices, crop_size=crop_size, method=method, | ||
extrapolation_value=extrapolation_value, name=name) | ||
|
||
|
||
############################################################ | ||
# Defining methods to use | ||
############################################################ | ||
if TF_MAJOR == 1 and 3 <= TF_MINOR <= 15: | ||
if TF_MINOR < 14: | ||
WHERE_FUNC = tf.where | ||
else: | ||
WHERE_FUNC = tf.compat.v1.where_v2 | ||
|
||
if TF_MINOR < 13: | ||
CROP_AND_RESIZE_FUNC = crop_and_resize_v1 | ||
INTERSECTION_FUNC = tf.sets.set_intersection | ||
else: # TF >= 1.13 | ||
CROP_AND_RESIZE_FUNC = crop_and_resize_v2 | ||
INTERSECTION_FUNC = tf.sets.intersection | ||
|
||
if TF_MINOR < 12: | ||
TO_DENSE_FUNC = tf.sparse_tensor_to_dense | ||
else: # TF >= 1.12 | ||
TO_DENSE_FUNC = tf.sparse.to_dense | ||
|
||
if TF_MINOR < 10: | ||
LOG_FUNC = tf.log | ||
else: # TF >= 1.10 | ||
LOG_FUNC = tf.math.log | ||
else: | ||
raise NotImplementedError(f"Compatibility with TF {tf.__version__} is not implemented") | ||
|
||
|
||
def crop_and_resize(image, boxes, box_indices=None, crop_size=None, method='bilinear', extrapolation_value=0, | ||
name=None): | ||
return CROP_AND_RESIZE_FUNC(image, boxes, box_indices, crop_size, method, extrapolation_value, name) | ||
|
||
|
||
def intersection(a, b, validate_indices=True): | ||
return INTERSECTION_FUNC(a=a, b=b, validate_indices=validate_indices) | ||
|
||
|
||
def log(x, name=None): | ||
return LOG_FUNC(x, name=name) | ||
|
||
|
||
def to_dense(sp_input, default_value=None, validate_indices=True, name=None): | ||
return TO_DENSE_FUNC(sp_input=sp_input, default_value=default_value, validate_indices=validate_indices, name=name) | ||
|
||
|
||
def where(condition, x=None, y=None, name=None): | ||
return WHERE_FUNC(condition=condition, x=x, y=y, name=name) |
Oops, something went wrong.