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

Deprecate Tensorflow-based methods (sct_deepseg_<x>) and use only PyTorch (sct_deepseg) #3046

Closed
joshuacwnewton opened this issue Nov 15, 2020 · 4 comments
Labels
enhancement category: improves performance/results of an existing feature epic Something big needs-discussion SCT API: deepseg_gm context: SCT API: deepseg_legion context: SCT API: deepseg_sc context: SCT API: deepseg context: sct_deepseg_gm context: sct_deepseg_lesion context: sct_deepseg_sc context: sct_deepseg context: Global entry point for all deep learning segmentation methods

Comments

@joshuacwnewton
Copy link
Member

joshuacwnewton commented Nov 15, 2020

Context

Historically, SCT has used Keras/tensorflow for its deep learning-based segmentation methods (sct_deepseg_sc, sct_deepseg_gm, sct_deepseg_lesion). However, #2639 introduced the more general sct_deepseg, which aims to provide alternatives that use pytorch instead. (More context in #2626.)

But, as noted in #2639, the transition is not complete:

For now, this new function will not replace sct_deepseg_X, but will be complementary to the existing functions, so we can gather feedback from users before making these functions deprecated. The "big" change will likely be associated with a major release.

Motivation

The main motivation to switch is to unify the development between SCT and ivadomed. Further information here: #2626 (comment)

Other benefits include:

  • Easier Python version support, because Tensorflow is typically the only blocker for upgrading Python versions:

    • tensorflow==1.5 ties us to Python 3.6, which is quickly approaching EOL (#3227).
    • tensorflow==1.15 ties us to Python 3.7. (#3367)
    • etc.

    Since PyTorch is the main library used by sister project ivadomed, and their development team has already spent much effort testing Python 3.7/3.8/3.9, becoming PyTorch-only helps to sync us up with ivadomed.

  • Fewer dependencies, so fewer upstream issues (e.g. #2987, #2562)

  • Security benefits (we're currently quietly ignoring many dependabot vulnerability warnings for Tensorflow.)

Next steps

There is a brief summary in #3227 (comment):

The bigger work is really to tie in the new model training with the git-annex datasets that @kousu is deploying. We also need to make some decisions on how we want to expose the models, what default models to install, how many flavors of these models (eg: SoftSeg vs. HardSeg), etc.

A more in-depth summary is provided here: https://gist.github.com/joshuacwnewton/c59f1aa0d805e7e2d912eafd99e38c6a

@joshuacwnewton joshuacwnewton added enhancement category: improves performance/results of an existing feature needs-discussion sct_deepseg_sc context: sct_deepseg_gm context: epic Something big sct_deepseg_lesion context: sct_deepseg context: Global entry point for all deep learning segmentation methods SCT API: deepseg context: SCT API: deepseg_gm context: SCT API: deepseg_legion context: SCT API: deepseg_sc context: labels Nov 15, 2020
@joshuacwnewton joshuacwnewton changed the title Deprecate Keras/Tensorflow-based methods (sct_deepseg_X) and use only PyTorch (sct_deepseg) Deprecate Tensorflow-based methods (sct_deepseg_<x>) and use only PyTorch (sct_deepseg) Apr 27, 2021
@joshuacwnewton joshuacwnewton pinned this issue Apr 29, 2021
@kousu
Copy link
Contributor

kousu commented Oct 5, 2021

Related: #3088

@kousu
Copy link
Contributor

kousu commented Oct 5, 2021

We talked at the weekly ivadomed meeting about this. My understanding of our conclusion is:

  1. There are efforts to train newer, better models

    1. sct_deepseg_gm has no active project that could replace it
    2. sct_deepseg_lesion: There is a project to make a better multiple-sclerosis lesion model (https://github.com/ivadomed/ms-challenge-2021/) as part of ivadomed
    3. sct_deepseg_sc: There is a project to make a contrast agnostic spine model (Train new model for spinal cord segmentation ivadomed/ivadomed#495, https://github.com/sct-pipeline/contrast-agnostic-softseg-spinalcord) as part of ivadomed

    These models are probably not going to be drop-in replacements. They will change the data type of input and output (e.g. going from binary to softseg, straightened vs unstraightened). They are also active research projects with research timelines, performance measurements and papers to be published. They won't be ready soon.

  2. There is support to do a shorter-term solution that does a more direct port. Either:

    1. Retrain on pytorch. Find the existing training data, scripts and their existing outputs:

      1. sct_deepseg_gm:
      2. sct_deepseg_lesion:
      3. sct_deepseg_sc:

      and port the necessary parts to pytorch. Retrain on the same data.

      Should be drop-in compatible since the input shapes are the same.

      Should be able to add these to ivadomed.

    2. Translate tensorflow -> ONNX (Remove dependency on Keras/Tensorflow by relying only on onnxruntime and ONNX models #3735)

    3. Translate tensorflow -> pytorch

@kousu
Copy link
Contributor

kousu commented Oct 5, 2021

@jcohenadad, please help me fill in the ????? above.

@joshuacwnewton
Copy link
Member Author

joshuacwnewton commented Jan 14, 2023

The original issue description highlights a number of benefits for moving away from Tensorflow:

  • Easier Python version support, because Tensorflow is typically the only blocker for upgrading Python versions:

    • tensorflow==1.5 ties us to Python 3.6, which is quickly approaching EOL (#3227).
    • tensorflow==1.15 ties us to Python 3.7. (#3367)
    • etc.

    Since PyTorch is the main library used by sister project ivadomed, and their development team has already spent much effort testing Python 3.7/3.8/3.9, becoming PyTorch-only helps to sync us up with ivadomed.

  • Fewer dependencies, so fewer upstream issues (e.g. #2987, #2562)

  • Security benefits (we're currently quietly ignoring many dependabot vulnerability warnings for Tensorflow.)

However, since the migration from Tensorflow to ONNX (#3735), we no longer struggle with any of these issues.

This means that there is much less motivation to retrain the sct_deepseg_<x> models using PyTorch. (I think the main benefit would be to unify the deepseg functions under a single umbrella, but this is more of a naming/organizational benefit than a functional benefit.)

I think, given this, it might be safe to close this issue in its entirety.

I could still recreate the issue in neuropoly/idea-projects as a project idea for future interns/students in the lab (as per #3947 and #3088 (comment)), but I'm not sure how high-priority such a task would be. (To me, it seems relatively low-priority.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement category: improves performance/results of an existing feature epic Something big needs-discussion SCT API: deepseg_gm context: SCT API: deepseg_legion context: SCT API: deepseg_sc context: SCT API: deepseg context: sct_deepseg_gm context: sct_deepseg_lesion context: sct_deepseg_sc context: sct_deepseg context: Global entry point for all deep learning segmentation methods
Projects
None yet
Development

No branches or pull requests

2 participants