diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..959d48e
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,13 @@
+include maps.txt
+include README.md
+include README.rst
+recursive-include data *
+README.txt
+setup.cfg
+setup.py
+maps.txt
+ivtmetrics/__init__.py
+ivtmetrics/detection.py
+ivtmetrics/disentangle.py
+ivtmetrics/recognition.py
+ivtmetrics/maps.txt
diff --git a/README.md b/README.md
index ba28050..93797af 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,3 @@
-
-
[![PyPI version](https://badge.fury.io/py/motmetrics.svg)](https://pypi.org/project/ivtmetrics/0.0.1/)
# ivtmetrics
@@ -7,39 +5,41 @@
The **ivtmetrics** library provides a Python implementation of metrics for benchmarking surgical action triplet detection and recognition.
## Features at a glance
-- *Recognition Evaluation*
-Provides AP metrics to measure the performance of a model on action triplet recognition.
-- *Detection Evaluation*
-Supports Intersection over Union distances measure of the triplet localization with respect to the instruments.
-- *Flexible Analysis*
- - Supports for switching between frame-wise to video-wise averaging of the AP.
- - Supports disentangle prediction and obtained filtered performance for the various components of the triplets as well as their association performances at various levels.
+
+The following are available with ivtmetrics:
+1. **Recognition Evaluation**: Provides AP metrics to measure the performance of a model on action triplet recognition.
+2. **Detection Evaluation**: Supports Intersection over Union distances measure of the triplet localization with respect to the instruments.
+3. **Flexible Analysis**: (1) Supports for switching between frame-wise to video-wise averaging of the AP.
+(2) Supports disentangle prediction and obtained filtered performance for the various components of the triplets as well as their association performances at various levels.
## Installation
+
### Install via PyPi
+
To install **ivtmetrics** use `pip`
```
pip install ivtmetrics
```
-Python 3.5-3.9 and numpy and scikit-learn are required.
### Install via Conda
+
```
conda install -c nwoye ivtmetrics
```
+Python 3.5-3.9 and numpy and scikit-learn are required.
+
## Metrics
The metrics have been aligned with what is reported by [CholecT50](https://arxiv.org/abs/2109.03223) benchmark.
**ivtmetrics** can be imported in the following way:
-```python
+``` python
import ivtmetrics
-
```
The metrics implement both **recognition** and **detection** evaluation.
@@ -49,51 +49,55 @@ The metrics internally implement a disentangle function to help filter the tripl
**Recognition ivtmetrics** can be used in the following ways:
-```python
+``` python
metric = ivtmetrics.Recognition(num_class)
-
```
This takes an argument `num_class` which is default to `100`
-The following function are possible with the 'Recognition` class:
-Name|Description
-:---|:---
+The following function are possible with the `Recognition` class:
+
+Name | Description
+:--- | :---
update(`targets, predictions`)|takes in a (batch of) vector predictions and their corresponding groundtruth. vector size must match `num_class` in the class initialization.
video_end()|Call to make the end of one video sequence.
reset()|Reset current records. Useful during training and can be called at the begining of each epoch to avoid overlapping epoch performances.
reset_global()|Reset all records. Useful for switching between training/validation/testing or can be called at the begining of new experiment.
-compute_AP(`component, ignore_null`)|Obtain the average precision on the fly. This gives the AP only on examples cases after the last `reset()` call. Useful for epoch performance during training.
- args `component` can be any of the following ('i', 'v', 't', 'iv', 'it','ivt') to compute performance for (instrument, verb, target, instrument-verb, instrument-target, instrument-verb-target) respectively. default is 'ivt' for triplets.
- args `ignore_null` (optional, default=False): to ignore null triplet classes in the evaluation. This option is enabled in CholecTriplet2021 challenge.
- the output is a `dict` with keys("AP", "mAP") for per-class and mean AP respectively.
+compute_AP(`component, ignore_null`)|Obtain the average precision on the fly. This gives the AP only on examples cases after the last `reset()` call. Useful for epoch performance during training.
compute_video_AP(`component, ignore_null`)|(RECOMMENDED) compute video-wise AP performance as used in CholecT50 benchmarks.
compute_global_AP(`component, ignore_null`)|compute frame-wise AP performance for all seen samples.
topK(`k, component`) | Obtain top K performance on action triplet recognition for all seen examples. args `k` can be any int between 1-99. k = [5,10,15,20] have been used in benchmark papers.
topClass(`k, component`)|Obtain top K recognized classes on action triplet recognition for all seen examples. args `k` can be any int between 1-99. k = 10 have been used in benchmark papers.
+### args:
+- args `component` can be any of the following ('i', 'v', 't', 'iv', 'it','ivt') to compute performance for (instrument, verb, target, instrument-verb, instrument-target, instrument-verb-target) respectively. default is 'ivt' for triplets.
+- args `ignore_null` (optional, default=False): to ignore null triplet classes in the evaluation. This option is enabled in CholecTriplet2021 challenge.
+- the output is a `dict` with keys("AP", "mAP") for per-class and mean AP respectively.
+
+
+
+
#### Example usage
+
+
```python
import ivtmetrics
recognize = ivtmetrics.Recognition(num_class=100)
-
-network = MyModel(...) # your model here
-
+network = MyModel(...) # your model here
# training
-for epoch in number of epochs:
+for epoch in number-of-epochs:
recognize.reset()
for images, labels in dataloader(...): # your data loader
- predictions = network(image)
- recognize.update(labels, predictions)
-
+ predictions = network(image)
+ recognize.update(labels, predictions)
results_i = recognize.compute_AP('i')
print("instrument per class AP", results_i["AP"])
print("instrument mean AP", results_i["mAP"])
-
results_ivt = recognize.compute_AP('ivt')
print("triplet mean AP", results_ivt["mAP"])
-
-
# evaluation
recognize.reset_global()
@@ -130,30 +134,46 @@ metric = ivtmetrics.Detection(num_class, num_tool)
```
This takes an argument `num_class` which is default to `100` and `num_tool` which is default to `6`
-The following function are possible with the 'Recognition` class:
-Name|Description
-:---|:---
-update(`targets, predictions, format`)|input: takes in a (batch of) list/dict predictions and their corresponding groundtruth. Each frame prediction/groundtruth can be either as a `list of list` or `list of dict`. - (a) **list of list format**: [[tripletID, toolID, toolProbs, x, y, w, h], [tripletID, toolID, toolProbs, x, y, w, h], ...] where:
- `tripletID` = triplet unique identity
- `toolID` = instrument unique identity
- `toolProbs` = instrument detection confidence
- `x` = bounding box x1 coordiante
- `y` = bounding box y1 coordinate
- `w` = width of the box
- `h` = height of the box
- The [x,y,w,h] are scaled between 0..1
- (b) **list of dict format**: [{"triplet":tripletID, "instrument":[toolID, toolProbs, x, y, w, h]}, {"triplet":tripletID, "instrument":[toolID, toolProbs, x, y, w, h]}, ...].
- The `format` args describes the input format with either of the values ("list", "dict")
+The following function are possible with the `Detection` class:
+
+Name | Description
+:--- | :---
+update(`targets, predictions, format`)|input: takes in a (batch of) list/dict predictions and their corresponding groundtruth. Each frame prediction/groundtruth can be either as a `list of list` or `list of dict`.
video_end()|Call to make the end of one video sequence.
reset()|Reset current records. Useful during training and can be called at the begining of each epoch to avoid overlapping epoch performances.
reset_global()|Reset all records. Useful for switching between training/validation/testing or can be called at the begining of new experiment.
-compute_AP(`component`)|Obtain the average precision on the fly. This gives the AP only on examples cases after the last `reset()` call. Useful for epoch performance during training.- args `component` can be any of the following ('i', 'v', 't', 'iv', 'it','ivt') to compute performance for (instrument, verb, target, instrument-verb, instrument-target, instrument-verb-target) respectively.
- default is 'ivt' for triplets.
- the output is a `dict` with keys("AP", "mAP", "Rec", "mRec", "Pre", "mPre") for per-class AP, mean AP, per-class Recall, mean Recall, per-class Precision and mean Precision respectively.
+compute_AP(`component`)|Obtain the average precision on the fly. This gives the AP only on examples cases after the last `reset()` call. Useful for epoch performance during training.
compute_video_AP(`component`)|(RECOMMENDED) compute video-wise AP performance as used in CholecT50 benchmarks.
compute_global_AP(`component`)|compute frame-wise AP performance for all seen samples.
+### args:
+1. **list of list format**: [[tripletID, toolID, toolProbs, x, y, w, h], [tripletID, toolID, toolProbs, x, y, w, h], ...], where:
+ * `tripletID` = triplet unique identity
+ * `toolID` = instrument unique identity
+ * `toolProbs` = instrument detection confidence
+ * `x` = bounding box x1 coordiante
+ * `y` = bounding box y1 coordinate
+ * `w` = width of the box
+ * `h` = height of the box
+ * The [x,y,w,h] are scaled between 0..1
+2. **list of dict format**: [{"triplet":tripletID, "instrument":[toolID, toolProbs, x, y, w, h]}, {"triplet":tripletID, "instrument":[toolID, toolProbs, x, y, w, h]}, ...].
+3. `format` args describes the input format with either of the values ("list", "dict")
+4. `component` can be any of the following ('i', 'v', 't', 'iv', 'it','ivt') to compute performance for (instrument, verb, target, instrument-verb, instrument-target, instrument-verb-target) respectively, default is 'ivt' for triplets.<
+* the output is a `dict` with keys("AP", "mAP", "Rec", "mRec", "Pre", "mPre") for per-class AP, mean AP, per-class Recall, mean Recall, per-class Precision and mean Precision respectively.
#### Example usage
-```python
+``` python
import ivtmetrics
detect = ivtmetrics.Detection(num_class=100)
network = MyModel(...) # your model here
# training
+
format = "list"
for epoch in number of epochs:
for images, labels in dataloader(...): # your data loader
@@ -171,6 +191,7 @@ for epoch in number of epochs:
# evaluation
+
format = "dict"
for video in videos:
for images, labels in dataloader(video, ..): # your data loader
@@ -192,11 +213,13 @@ Any `nan` value in results is for classes with no occurrence in the data sample.
## Docker
+
coming soon ..
# Citation
+
If you use this metrics in your project or research, please consider citing the associated publication:
```
@article{nwoye2021rendezvous,
@@ -212,6 +235,7 @@ If you use this metrics in your project or research, please consider citing the
### References
+
1. Nwoye, C. I., Yu, T., Gonzalez, C., Seeliger, B., Mascagni, P., Mutter, D., ... & Padoy, N. (2021). Rendezvous: Attention Mechanisms for the Recognition of Surgical Action Triplets in Endoscopic Videos. arXiv preprint arXiv:2109.03223.
2. Nwoye, C. I., Gonzalez, C., Yu, T., Mascagni, P., Mutter, D., Marescaux, J., & Padoy, N. (2020, October). Recognition of instrument-tissue interactions in endoscopic videos via action triplets. In International Conference on Medical Image Computing and Computer-Assisted Intervention (pp. 364-374). Springer, Cham.
3. https://cholectriplet2021.grand-challenge.org
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..b8f0b72
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,370 @@
+|PyPI version|
+
+ivtmetrics
+==========
+
+The **ivtmetrics** library provides a Python implementation of metrics
+for benchmarking surgical action triplet detection and recognition.
+
+Features at a glance
+--------------------
+
+The following are available with ivtmetrics: 1. **Recognition
+Evaluation**: Provides AP metrics to measure the performance of a model
+on action triplet recognition. 2. **Detection Evaluation**: Supports
+Intersection over Union distances measure of the triplet localization
+with respect to the instruments. 3. **Flexible Analysis**: (1) Supports
+for switching between frame-wise to video-wise averaging of the AP. (2)
+Supports disentangle prediction and obtained filtered performance for
+the various components of the triplets as well as their association
+performances at various levels.
+
+## Installation
+
+Install via PyPi
+~~~~~~~~~~~~~~~~
+
+To install **ivtmetrics** use ``pip``
+
+::
+
+ pip install ivtmetrics
+
+Install via Conda
+~~~~~~~~~~~~~~~~~
+
+::
+
+ conda install -c nwoye ivtmetrics
+
+Python 3.5-3.9 and numpy and scikit-learn are required.
+
+## Metrics
+
+The metrics have been aligned with what is reported by
+`CholecT50 `__ benchmark.
+**ivtmetrics** can be imported in the following way:
+
+.. code:: python
+
+ import ivtmetrics
+
+The metrics implement both **recognition** and **detection** evaluation.
+The metrics internally implement a disentangle function to help filter
+the triplet components as well as triplet different levels of
+association.
+
+Recognition Metrics
+~~~~~~~~~~~~~~~~~~~
+
+**Recognition ivtmetrics** can be used in the following ways:
+
+.. code:: python
+
+ metric = ivtmetrics.Recognition(num_class)
+
+This takes an argument ``num_class`` which is default to ``100``
+
+The following function are possible with the ``Recognition`` class:
+
++-----------------------------------+-----------------------------------+
+| Name | Description |
++===================================+===================================+
+| update(``targets, predictions``) | takes in a (batch of) vector |
+| | predictions and their |
+| | corresponding groundtruth. vector |
+| | size must match ``num_class`` in |
+| | the class initialization. |
++-----------------------------------+-----------------------------------+
+| video_end() | Call to make the end of one video |
+| | sequence. |
++-----------------------------------+-----------------------------------+
+| reset() | Reset current records. Useful |
+| | during training and can be called |
+| | at the begining of each epoch to |
+| | avoid overlapping epoch |
+| | performances. |
++-----------------------------------+-----------------------------------+
+| reset_global() | Reset all records. Useful for |
+| | switching between |
+| | training/validation/testing or |
+| | can be called at the begining of |
+| | new experiment. |
++-----------------------------------+-----------------------------------+
+| compu | Obtain the average precision on |
+| te_AP(``component, ignore_null``) | the fly. This gives the AP only |
+| | on examples cases after the last |
+| | ``reset()`` call. Useful for |
+| | epoch performance during |
+| | training. |
++-----------------------------------+-----------------------------------+
+| compute_vid | (RECOMMENDED) compute video-wise |
+| eo_AP(``component, ignore_null``) | AP performance as used in |
+| | CholecT50 benchmarks. |
++-----------------------------------+-----------------------------------+
+| compute_glob | compute frame-wise AP performance |
+| al_AP(``component, ignore_null``) | for all seen samples. |
++-----------------------------------+-----------------------------------+
+| topK(``k, component``) | Obtain top K performance on |
+| | action triplet recognition for |
+| | all seen examples. args ``k`` can |
+| | be any int between 1-99. k = |
+| | [5,10,15,20] have been used in |
+| | benchmark papers. |
++-----------------------------------+-----------------------------------+
+| topClass(``k, component``) | Obtain top K recognized classes |
+| | on action triplet recognition for |
+| | all seen examples. args ``k`` can |
+| | be any int between 1-99. k = 10 |
+| | have been used in benchmark |
+| | papers. |
++-----------------------------------+-----------------------------------+
+
+args:
+~~~~~
+
+- args ``component`` can be any of the following (‘i’, ‘v’, ‘t’, ‘iv’,
+ ‘it’,‘ivt’) to compute performance for (instrument, verb, target,
+ instrument-verb, instrument-target, instrument-verb-target)
+ respectively. default is ‘ivt’ for triplets.
+- args ``ignore_null`` (optional, default=False): to ignore null
+ triplet classes in the evaluation. This option is enabled in
+ CholecTriplet2021 challenge.
+- the output is a ``dict`` with keys(“AP”, “mAP”) for per-class and
+ mean AP respectively.
+
+#### Example usage
+
+.. code:: python
+
+ import ivtmetrics
+ recognize = ivtmetrics.Recognition(num_class=100)
+ network = MyModel(...) # your model here
+ # training
+ for epoch in number-of-epochs:
+ recognize.reset()
+ for images, labels in dataloader(...): # your data loader
+ predictions = network(image)
+ recognize.update(labels, predictions)
+ results_i = recognize.compute_AP('i')
+ print("instrument per class AP", results_i["AP"])
+ print("instrument mean AP", results_i["mAP"])
+ results_ivt = recognize.compute_AP('ivt')
+ print("triplet mean AP", results_ivt["mAP"])
+
+ # evaluation
+ recognize.reset_global()
+ for video in videos:
+ for images, labels in dataloader(video, ..): # your data loader
+ predictions = network(image)
+ recognize.update(labels, predictions)
+ recognize.video_end()
+
+ results_i = recognize.compute_video_AP('i')
+ print("instrument per class AP", results_i["AP"])
+ print("instrument mean AP", results_i["mAP"])
+
+ results_it = recognize.compute_video_AP('it')
+ print("instrument-target mean AP", results_it["mAP"])
+
+ results_ivt = recognize.compute_video_AP('ivt')
+ print("triplet mean AP", results_ivt["mAP"])
+
+Any ``nan`` value in results is for classes with no occurrence in the
+data sample.
+
+Detection Metrics
+~~~~~~~~~~~~~~~~~
+
+**Detection ivtmetrics** can be used in the following ways:
+
+.. code:: python
+
+ metric = ivtmetrics.Detection(num_class, num_tool)
+
+This takes an argument ``num_class`` which is default to ``100`` and
+``num_tool`` which is default to ``6``
+
+The following function are possible with the ``Detection`` class:
+
++-----------------------------------+-----------------------------------+
+| Name | Description |
++===================================+===================================+
+| update( | input: takes in a (batch of) |
+| ``targets, predictions, format``) | list/dict predictions and their |
+| | corresponding groundtruth. Each |
+| | frame prediction/groundtruth can |
+| | be either as a ``list of list`` |
+| | or ``list of dict``. |
++-----------------------------------+-----------------------------------+
+| video_end() | Call to make the end of one video |
+| | sequence. |
++-----------------------------------+-----------------------------------+
+| reset() | Reset current records. Useful |
+| | during training and can be called |
+| | at the begining of each epoch to |
+| | avoid overlapping epoch |
+| | performances. |
++-----------------------------------+-----------------------------------+
+| reset_global() | Reset all records. Useful for |
+| | switching between |
+| | training/validation/testing or |
+| | can be called at the begining of |
+| | new experiment. |
++-----------------------------------+-----------------------------------+
+| compute_AP(``component``) | Obtain the average precision on |
+| | the fly. This gives the AP only |
+| | on examples cases after the last |
+| | ``reset()`` call. Useful for |
+| | epoch performance during |
+| | training. |
++-----------------------------------+-----------------------------------+
+| compute_video_AP(``component``) | (RECOMMENDED) compute video-wise |
+| | AP performance as used in |
+| | CholecT50 benchmarks. |
++-----------------------------------+-----------------------------------+
+| compute_global_AP(``component``) | compute frame-wise AP performance |
+| | for all seen samples. |
++-----------------------------------+-----------------------------------+
+
+.. _args-1:
+
+args:
+~~~~~
+
+1. **list of list format**: [[tripletID, toolID, toolProbs, x, y, w, h],
+ [tripletID, toolID, toolProbs, x, y, w, h], …], where:
+
+ - ``tripletID`` = triplet unique identity
+ - ``toolID`` = instrument unique identity
+ - ``toolProbs`` = instrument detection confidence
+ - ``x`` = bounding box x1 coordiante
+ - ``y`` = bounding box y1 coordinate
+ - ``w`` = width of the box
+ - ``h`` = height of the box
+ - The [x,y,w,h] are scaled between 0..1
+
+2. **list of dict format**: [{“triplet”:tripletID, “instrument”:[toolID,
+ toolProbs, x, y, w, h]}, {“triplet”:tripletID, “instrument”:[toolID,
+ toolProbs, x, y, w, h]}, …].
+3. ``format`` args describes the input format with either of the values
+ (“list”, “dict”)
+4. ``component`` can be any of the following (‘i’, ‘v’, ‘t’, ‘iv’,
+ ‘it’,‘ivt’) to compute performance for (instrument, verb, target,
+ instrument-verb, instrument-target, instrument-verb-target)
+ respectively, default is ‘ivt’ for triplets.<
+
+- the output is a ``dict`` with keys(“AP”, “mAP”, “Rec”, “mRec”, “Pre”,
+ “mPre”) for per-class AP, mean AP, per-class Recall, mean Recall,
+ per-class Precision and mean Precision respectively.
+
+#### Example usage
+
+.. code:: python
+
+ import ivtmetrics
+ detect = ivtmetrics.Detection(num_class=100)
+
+ network = MyModel(...) # your model here
+
+ # training
+
+ format = "list"
+ for epoch in number of epochs:
+ for images, labels in dataloader(...): # your data loader
+ predictions = network(image)
+ labels, predictions = formatYourLabels(labels, predictions)
+ detect.update(labels, predictions, format=format)
+
+ results_i = detect.compute_AP('i')
+ print("instrument per class AP", results_i["AP"])
+ print("instrument mean AP", results_i["mAP"])
+
+ results_ivt = detect.compute_AP('ivt')
+ print("triplet mean AP", results_ivt["mAP"])
+ detect.reset()
+
+
+ # evaluation
+
+ format = "dict"
+ for video in videos:
+ for images, labels in dataloader(video, ..): # your data loader
+ predictions = network(image)
+ labels, predictions = formatYourLabels(labels, predictions)
+ detect.update(labels, predictions, format=format)
+ detect.video_end()
+
+ results_ivt = detect.compute_video_AP('ivt')
+ print("triplet mean AP", results_ivt["mAP"])
+ print("triplet mean recall", results_ivt["mRec"])
+ print("triplet mean precision", results_ivt["mPre"])
+
+Any ``nan`` value in results is for classes with no occurrence in the
+data sample.
+
+## Docker
+
+coming soon ..
+
+# Citation
+
+If you use this metrics in your project or research, please consider
+citing the associated publication:
+
+::
+
+ @article{nwoye2021rendezvous,
+ title={Rendezvous: Attention Mechanisms for the Recognition of Surgical Action Triplets in Endoscopic Videos},
+ author={Nwoye, Chinedu Innocent and Yu, Tong and Gonzalez, Cristians and Seeliger, Barbara and Mascagni, Pietro and Mutter, Didier and Marescaux, Jacques and Padoy, Nicolas},
+ journal={arXiv preprint arXiv:2109.03223},
+ year={2021}
+ }
+
+### References
+
+1. Nwoye, C. I., Yu, T., Gonzalez, C., Seeliger, B., Mascagni, P.,
+ Mutter, D., … & Padoy, N. (2021). Rendezvous: Attention Mechanisms
+ for the Recognition of Surgical Action Triplets in Endoscopic Videos.
+ arXiv preprint arXiv:2109.03223.
+2. Nwoye, C. I., Gonzalez, C., Yu, T., Mascagni, P., Mutter, D.,
+ Marescaux, J., & Padoy, N. (2020, October). Recognition of
+ instrument-tissue interactions in endoscopic videos via action
+ triplets. In International Conference on Medical Image Computing and
+ Computer-Assisted Intervention (pp. 364-374). Springer, Cham.
+3. https://cholectriplet2021.grand-challenge.org
+4. http://camma.u-strasbg.fr/datasets
+
+License
+-------
+
+::
+
+ BSD 2-Clause License
+
+ Copyright (c) 2022, Research Group CAMMA
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.```
+
+.. |PyPI version| image:: https://badge.fury.io/py/motmetrics.svg
+ :target: https://pypi.org/project/ivtmetrics/0.0.1/
diff --git a/README.txt b/README.txt
deleted file mode 100644
index ba28050..0000000
--- a/README.txt
+++ /dev/null
@@ -1,250 +0,0 @@
-
-
-[![PyPI version](https://badge.fury.io/py/motmetrics.svg)](https://pypi.org/project/ivtmetrics/0.0.1/)
-
-# ivtmetrics
-
-The **ivtmetrics** library provides a Python implementation of metrics for benchmarking surgical action triplet detection and recognition.
-
-## Features at a glance
-- *Recognition Evaluation*
-Provides AP metrics to measure the performance of a model on action triplet recognition.
-- *Detection Evaluation*
-Supports Intersection over Union distances measure of the triplet localization with respect to the instruments.
-- *Flexible Analysis*
- - Supports for switching between frame-wise to video-wise averaging of the AP.
- - Supports disentangle prediction and obtained filtered performance for the various components of the triplets as well as their association performances at various levels.
-
-
-
-
-## Installation
-### Install via PyPi
-To install **ivtmetrics** use `pip`
-```
-pip install ivtmetrics
-```
-Python 3.5-3.9 and numpy and scikit-learn are required.
-
-### Install via Conda
-```
-conda install -c nwoye ivtmetrics
-```
-
-
-## Metrics
-
-The metrics have been aligned with what is reported by [CholecT50](https://arxiv.org/abs/2109.03223) benchmark.
-**ivtmetrics** can be imported in the following way:
-
-```python
-import ivtmetrics
-
-```
-
-The metrics implement both **recognition** and **detection** evaluation.
-The metrics internally implement a disentangle function to help filter the triplet components as well as triplet different levels of association.
-
-### Recognition Metrics
-
-**Recognition ivtmetrics** can be used in the following ways:
-
-```python
-metric = ivtmetrics.Recognition(num_class)
-
-```
-This takes an argument `num_class` which is default to `100`
-
-The following function are possible with the 'Recognition` class:
-Name|Description
-:---|:---
-update(`targets, predictions`)|takes in a (batch of) vector predictions and their corresponding groundtruth. vector size must match `num_class` in the class initialization.
-video_end()|Call to make the end of one video sequence.
-reset()|Reset current records. Useful during training and can be called at the begining of each epoch to avoid overlapping epoch performances.
-reset_global()|Reset all records. Useful for switching between training/validation/testing or can be called at the begining of new experiment.
-compute_AP(`component, ignore_null`)|Obtain the average precision on the fly. This gives the AP only on examples cases after the last `reset()` call. Useful for epoch performance during training. - args `component` can be any of the following ('i', 'v', 't', 'iv', 'it','ivt') to compute performance for (instrument, verb, target, instrument-verb, instrument-target, instrument-verb-target) respectively. default is 'ivt' for triplets.
- args `ignore_null` (optional, default=False): to ignore null triplet classes in the evaluation. This option is enabled in CholecTriplet2021 challenge.
- the output is a `dict` with keys("AP", "mAP") for per-class and mean AP respectively.
-compute_video_AP(`component, ignore_null`)|(RECOMMENDED) compute video-wise AP performance as used in CholecT50 benchmarks.
-compute_global_AP(`component, ignore_null`)|compute frame-wise AP performance for all seen samples.
-topK(`k, component`) | Obtain top K performance on action triplet recognition for all seen examples. args `k` can be any int between 1-99. k = [5,10,15,20] have been used in benchmark papers.
-topClass(`k, component`)|Obtain top K recognized classes on action triplet recognition for all seen examples. args `k` can be any int between 1-99. k = 10 have been used in benchmark papers.
-
-
-
-
-#### Example usage
-
-```python
-import ivtmetrics
-recognize = ivtmetrics.Recognition(num_class=100)
-
-network = MyModel(...) # your model here
-
-# training
-for epoch in number of epochs:
- recognize.reset()
- for images, labels in dataloader(...): # your data loader
- predictions = network(image)
- recognize.update(labels, predictions)
-
- results_i = recognize.compute_AP('i')
- print("instrument per class AP", results_i["AP"])
- print("instrument mean AP", results_i["mAP"])
-
- results_ivt = recognize.compute_AP('ivt')
- print("triplet mean AP", results_ivt["mAP"])
-
-
-
-# evaluation
-recognize.reset_global()
-for video in videos:
- for images, labels in dataloader(video, ..): # your data loader
- predictions = network(image)
- recognize.update(labels, predictions)
- recognize.video_end()
-
-results_i = recognize.compute_video_AP('i')
-print("instrument per class AP", results_i["AP"])
-print("instrument mean AP", results_i["mAP"])
-
-results_it = recognize.compute_video_AP('it')
-print("instrument-target mean AP", results_it["mAP"])
-
-results_ivt = recognize.compute_video_AP('ivt')
-print("triplet mean AP", results_ivt["mAP"])
-```
-
-Any `nan` value in results is for classes with no occurrence in the data sample.
-
-
-
-
-
-### Detection Metrics
-
-**Detection ivtmetrics** can be used in the following ways:
-
-```python
-metric = ivtmetrics.Detection(num_class, num_tool)
-
-```
-This takes an argument `num_class` which is default to `100` and `num_tool` which is default to `6`
-
-The following function are possible with the 'Recognition` class:
-Name|Description
-:---|:---
-update(`targets, predictions, format`)|input: takes in a (batch of) list/dict predictions and their corresponding groundtruth. Each frame prediction/groundtruth can be either as a `list of list` or `list of dict`. - (a) **list of list format**: [[tripletID, toolID, toolProbs, x, y, w, h], [tripletID, toolID, toolProbs, x, y, w, h], ...] where:
- `tripletID` = triplet unique identity
- `toolID` = instrument unique identity
- `toolProbs` = instrument detection confidence
- `x` = bounding box x1 coordiante
- `y` = bounding box y1 coordinate
- `w` = width of the box
- `h` = height of the box
- The [x,y,w,h] are scaled between 0..1
- (b) **list of dict format**: [{"triplet":tripletID, "instrument":[toolID, toolProbs, x, y, w, h]}, {"triplet":tripletID, "instrument":[toolID, toolProbs, x, y, w, h]}, ...].
- The `format` args describes the input format with either of the values ("list", "dict")
-video_end()|Call to make the end of one video sequence.
-reset()|Reset current records. Useful during training and can be called at the begining of each epoch to avoid overlapping epoch performances.
-reset_global()|Reset all records. Useful for switching between training/validation/testing or can be called at the begining of new experiment.
-compute_AP(`component`)|Obtain the average precision on the fly. This gives the AP only on examples cases after the last `reset()` call. Useful for epoch performance during training.- args `component` can be any of the following ('i', 'v', 't', 'iv', 'it','ivt') to compute performance for (instrument, verb, target, instrument-verb, instrument-target, instrument-verb-target) respectively.
- default is 'ivt' for triplets.
- the output is a `dict` with keys("AP", "mAP", "Rec", "mRec", "Pre", "mPre") for per-class AP, mean AP, per-class Recall, mean Recall, per-class Precision and mean Precision respectively.
-compute_video_AP(`component`)|(RECOMMENDED) compute video-wise AP performance as used in CholecT50 benchmarks.
-compute_global_AP(`component`)|compute frame-wise AP performance for all seen samples.
-
-
-
-
-
-#### Example usage
-
-```python
-import ivtmetrics
-detect = ivtmetrics.Detection(num_class=100)
-
-network = MyModel(...) # your model here
-
-# training
-format = "list"
-for epoch in number of epochs:
- for images, labels in dataloader(...): # your data loader
- predictions = network(image)
- labels, predictions = formatYourLabels(labels, predictions)
- detect.update(labels, predictions, format=format)
-
- results_i = detect.compute_AP('i')
- print("instrument per class AP", results_i["AP"])
- print("instrument mean AP", results_i["mAP"])
-
- results_ivt = detect.compute_AP('ivt')
- print("triplet mean AP", results_ivt["mAP"])
- detect.reset()
-
-
-# evaluation
-format = "dict"
-for video in videos:
- for images, labels in dataloader(video, ..): # your data loader
- predictions = network(image)
- labels, predictions = formatYourLabels(labels, predictions)
- detect.update(labels, predictions, format=format)
- detect.video_end()
-
-results_ivt = detect.compute_video_AP('ivt')
-print("triplet mean AP", results_ivt["mAP"])
-print("triplet mean recall", results_ivt["mRec"])
-print("triplet mean precision", results_ivt["mPre"])
-```
-
-Any `nan` value in results is for classes with no occurrence in the data sample.
-
-
-
-
-
-## Docker
-coming soon ..
-
-
-
-# Citation
-If you use this metrics in your project or research, please consider citing the associated publication:
-```
-@article{nwoye2021rendezvous,
- title={Rendezvous: Attention Mechanisms for the Recognition of Surgical Action Triplets in Endoscopic Videos},
- author={Nwoye, Chinedu Innocent and Yu, Tong and Gonzalez, Cristians and Seeliger, Barbara and Mascagni, Pietro and Mutter, Didier and Marescaux, Jacques and Padoy, Nicolas},
- journal={arXiv preprint arXiv:2109.03223},
- year={2021}
-}
-```
-
-
-
-
-
-### References
-1. Nwoye, C. I., Yu, T., Gonzalez, C., Seeliger, B., Mascagni, P., Mutter, D., ... & Padoy, N. (2021). Rendezvous: Attention Mechanisms for the Recognition of Surgical Action Triplets in Endoscopic Videos. arXiv preprint arXiv:2109.03223.
-2. Nwoye, C. I., Gonzalez, C., Yu, T., Mascagni, P., Mutter, D., Marescaux, J., & Padoy, N. (2020, October). Recognition of instrument-tissue interactions in endoscopic videos via action triplets. In International Conference on Medical Image Computing and Computer-Assisted Intervention (pp. 364-374). Springer, Cham.
-3. https://cholectriplet2021.grand-challenge.org
-4. http://camma.u-strasbg.fr/datasets
-
-
-
-## License
-```
-BSD 2-Clause License
-
-Copyright (c) 2022, Research Group CAMMA
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-1. Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-
-2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.```
-```
-
diff --git a/ivtmetrics/__init__.py b/ivtmetrics/__init__.py
index 8913f09..9fb401d 100644
--- a/ivtmetrics/__init__.py
+++ b/ivtmetrics/__init__.py
@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
__library__ = "ivtmetrics"
-__version__ = "0.0.2"
+__version__ = "0.0.4"
__author__ = 'Chinedu Nwoye'
__supervisor__ = 'Nicolas Padoy'
__credits__ = 'CAMMA, ICube Lab, University of Strasbourg, France'
diff --git a/ivtmetrics/disentangle.py b/ivtmetrics/disentangle.py
index 91ff0f0..dc659f3 100644
--- a/ivtmetrics/disentangle.py
+++ b/ivtmetrics/disentangle.py
@@ -26,7 +26,7 @@ class Disentangle(object):
call filter a component labels from the inputs labels
"""
- def __init__(self, url="./maps.txt"):
+ def __init__(self, url="maps.txt"):
self.bank = np.genfromtxt(url, dtype=int, comments='#', delimiter=',', skip_header=0)
def decompose(self, inputs, component):
diff --git a/maps.txt b/maps.txt
deleted file mode 100644
index 883ba76..0000000
--- a/maps.txt
+++ /dev/null
@@ -1,101 +0,0 @@
-# IVT, I, V, T, IV, IT
-0,0,2,1,2,1
-1,0,2,0,2,0
-2,0,2,10,2,10
-3,0,0,3,0,3
-4,0,0,2,0,2
-5,0,0,4,0,4
-6,0,0,1,0,1
-7,0,0,0,0,0
-8,0,0,12,0,12
-9,0,0,8,0,8
-10,0,0,10,0,10
-11,0,0,11,0,11
-12,0,0,13,0,13
-13,0,8,0,8,0
-14,0,1,2,1,2
-15,0,1,4,1,4
-16,0,1,1,1,1
-17,0,1,0,1,0
-18,0,1,12,1,12
-19,0,1,8,1,8
-20,0,1,10,1,10
-21,0,1,11,1,11
-22,1,3,7,13,22
-23,1,3,5,13,20
-24,1,3,3,13,18
-25,1,3,2,13,17
-26,1,3,4,13,19
-27,1,3,1,13,16
-28,1,3,0,13,15
-29,1,3,8,13,23
-30,1,3,10,13,25
-31,1,3,11,13,26
-32,1,2,9,12,24
-33,1,2,3,12,18
-34,1,2,2,12,17
-35,1,2,1,12,16
-36,1,2,0,12,15
-37,1,2,10,12,25
-38,1,0,1,10,16
-39,1,0,8,10,23
-40,1,0,13,10,28
-41,1,1,2,11,17
-42,1,1,4,11,19
-43,1,1,0,11,15
-44,1,1,8,11,23
-45,1,1,10,11,25
-46,2,3,5,23,35
-47,2,3,3,23,33
-48,2,3,2,23,32
-49,2,3,4,23,34
-50,2,3,1,23,31
-51,2,3,0,23,30
-52,2,3,8,23,38
-53,2,3,10,23,40
-54,2,5,5,25,35
-55,2,5,11,25,41
-56,2,2,5,22,35
-57,2,2,3,22,33
-58,2,2,2,22,32
-59,2,2,1,22,31
-60,2,2,0,22,30
-61,2,2,10,22,40
-62,2,2,11,22,41
-63,2,1,0,21,30
-64,2,1,8,21,38
-65,3,3,10,33,55
-66,3,5,9,35,54
-67,3,5,5,35,50
-68,3,5,3,35,48
-69,3,5,2,35,47
-70,3,5,1,35,46
-71,3,5,8,35,53
-72,3,5,10,35,55
-73,3,5,11,35,56
-74,3,2,1,32,46
-75,3,2,0,32,45
-76,3,2,10,32,55
-77,4,4,5,44,65
-78,4,4,3,44,63
-79,4,4,2,44,62
-80,4,4,4,44,64
-81,4,4,1,44,61
-82,5,6,6,56,81
-83,5,2,2,52,77
-84,5,2,4,52,79
-85,5,2,1,52,76
-86,5,2,0,52,75
-87,5,2,10,52,85
-88,5,7,7,57,82
-89,5,7,4,57,79
-90,5,7,8,57,83
-91,5,1,0,51,75
-92,5,1,8,51,83
-93,5,1,10,51,85
-94,0,9,14,9,14
-95,1,9,14,19,29
-96,2,9,14,29,44
-97,3,9,14,39,59
-98,4,9,14,49,74
-99,5,9,14,59,89
diff --git a/setup.cfg b/setup.cfg
index dd1198f..5aef279 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,2 +1,2 @@
[metadata]
-description-file = README.txt
+description-file = README.rst
diff --git a/setup.py b/setup.py
index f472186..628a469 100644
--- a/setup.py
+++ b/setup.py
@@ -1,18 +1,24 @@
from distutils.core import setup
+from pathlib import Path
+this_directory = Path(__file__).parent
+long_description = (this_directory / "README.rst").read_text()
+
setup(
name='ivtmetrics',
- version='0.0.2',
+ version='0.0.4',
packages=['ivtmetrics'],
author='Chinedu Nwoye',
author_email='nwoye@unistra.fr',
description='A Python evaluation metrics package for action triplet recognition',
keywords = ['triplet', 'average precision', 'AP'],
- long_description = open('README.txt').read(),
- long_description_content_type = "text/markdown",
+ long_description = long_description,
+ long_description_content_type ='text/x-rst',
url='https://github.com/CAMMA-public/ivtmetrics',
- download_url = 'https://github.com/CAMMA-public/ivtmetrics/archive/refs/tags/v0.0.2.tar.gz', # I explain this later on
+ download_url = 'https://github.com/CAMMA-public/ivtmetrics/archive/refs/tags/v0.0.4.tar.gz', # I explain this later on
license='BSD 2-clause', # Chose a license from here: https://help.github.com/articles/licensing-a-repository
+ package_data={'': ['ivtmetrics/maps.txt', 'README.md', 'README.rst']},
+ include_package_data=True,
install_requires=['scikit-learn',
'numpy',
],