question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Moving to tf.keras

See original GitHub issue

Hi. First of all thanks for your repo! Have you considered moving to tf.keras instead of using separate keras? It would make your repo compatible with new TF 2.0 out of the box while still being compatible with older versions of TF as well.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:11
  • Comments:19 (7 by maintainers)

github_iconTop GitHub Comments

10reactions
qubvelcommented, Jul 29, 2019

Hi @bonlime @lc0 @NiklasDL @chAwater @srikrishna0130 @northanapon @Tyler-D

I have prepared a lib update to work together with keras and tf.keras and need your help! If someone have a time to test it and give a feedback it would be great (autotests have been passed)!

Some words about update:

  1. API almost the same (moved get_preprocessing to root)
import segmentation_models as  sm

model = sm.Unet('resnet18')
preprocess_input = sm.get_preprocessing('resnet18')
  1. Choose your framework: a) If you have Keras installed -> lib will load with Keras, if not lib will load with tf.keras b) You can setup env var SM_FRAMEWORK="keras"/SM_FRAMEWORK="tf.keras" before import segmentation_models c) You can change framework in runtime
>>> import segmentation_models as sm
Segmentation models: using `keras` framework.
>>> sm.framework() 
'keras'
>>> sm.set_framework('tf.keras')
>>> sm.framework() 
'tf.keras'
  1. I have removed almost all custom objects, so now trained models (except efficientnets) can be loaded without importing segmentation moldes lib.
  2. You also can change image_data_format (may be useful to convert models (#69 ))
keras.set_image_data_format('channels_first`)

Installation

Now you can install it

$ pip install -U git+https://github.com/qubvel/segmentation_models@feature/tf.keras \
                 git+https://github.com/qubvel/classification_models@feature/tf.keras \
                 git+https://github.com/qubvel/efficientnet

Roll back:

pip install -U segmentation-models==0.2.1

Waiting for your feedback, thank you!

8reactions
qubvelcommented, Jul 16, 2019

Hi @bonlime Yes, I have such plans, I think it should be done in a way of keras-applications with possibility to define your framework (keras or tf.keras). I did not still move to tf.keras by myself, so cannot guarantee this process will be fast.

Next week I am going to start adopting classification-models to make this possible. Any advices, bug reports, testing, PRs from community are appreciated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

tf.keras.Model | TensorFlow v2.11.0
Model groups layers into an object with training and inference features.
Read more >
Inside TensorFlow: tf.Keras (Part 1) - YouTube
Take an inside look into the TensorFlow team's own internal training sessions--technical deep dives into TensorFlow by the very people who ...
Read more >
Keras vs. tf.keras: What's the difference in TensorFlow 2.0?
In this tutorial you'll discover the difference between Keras and tf.keras. You'll also learn what's new in TensorFlow 2.0.
Read more >
How to move a tensorflow.keras model to GPU - Stack Overflow
Create a state_dict like PyTorch · Get the model architecture as JSON · Clear the Keras session and delete the model instance ·...
Read more >
Moving from Keras to Pytorch - Towards Data Science
A Highly customizable Training Loop · Create stratified splits using train data · Loop through the splits. · Convert your train and CV...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found