Closed giild closed 1 year ago
Some additional information, in case someone else runs into the same issue. If I move backend setting to after the imports, load throws this error. Here is the log from console.
Using TensorFlow backend
2.12.0
Traceback (most recent call last):
File "/Users/peterlin/kaggle/ATD-keras/keras/convert_keras_to_json.py", line 98, in
'tuple' object has no attribute 'rank'
Call arguments received by layer 'res_net_backbone' (type ResNetBackbone): • inputs=<KerasTensor shape=(160, 256, 256, 3), dtype=float32, name=input_layer> • training=None • mask=None
Hi @giild ,
There is a this note already in documentation.
Note that the that the backend must be configured before importing keras_core, and the backend cannot be changed after the package has been imported.
Please refer the attached snapshot.
thanks for pointing out it was at the bottom. Not gonna lie, I looked at the home page several times and didn't even see it. I've been contributing to Apache for 20 years and often we have troubleshooting page/section for common errors. I would suggest moving the note above example and giving it more emphasis. It's too easy to miss the way it is formatted it right now. I've seen this countless times on a variety of apache projects. Often what apache devs thought was obvious wasn't due to how we formatted or organized the documentation.
Something else to consider. https://keras.io/keras_core/ is the official docs. Often, I refer to the source instead of docs out of habit. Would it make sense to update the readme on https://github.com/keras-team/keras-core with similar note? I know most devs would rather write code than docs and maintaining the same information in multiple places sucks. Maybe have the readme link to the official documentation URL to lessen the maintenance overhead.
@giild ,
Thanks for the explanation. I think we can add a note in README.md
for better visibility. I can create a PR once Team reviews this and gives nod.
I was testing a sample Kaggle competition notebook found here https://www.kaggle.com/competitions/rsna-2023-abdominal-trauma-detection/code
I wrote a simple script to load the model and ran into an issue. It took me a few days to figure out why.
if I set KERAS_BACKEND after importing keras libraries, models.load_model fails with a strange error. Once I moved line to the top, it got rid of the error. It would be good to update the documentation so that users can resolve this quickly without wasting a bunch of time. I tend to import all the libraries first and then set any environment variables after the imports. I can make a documentation pull request if that helps.
import os
backend must be set before loading keras_core to avoid load errors
os.environ["KERAS_BACKEND"] = "tensorflow" import sys import keras_cv import keras_core as keras from keras_core import layers
import numpy as np import pandas as pd import tensorflow as tf
class Config: SEED = 61 IMAGE_SIZE = [256, 256] BATCH_SIZE = 160 EPOCHS = 10 TARGET_COLS = [ "bowel_injury", "extravasation_injury", "kidney_healthy", "kidney_low", "kidney_high", "liver_healthy", "liver_low", "liver_high", "spleen_healthy", "spleen_low", "spleen_high", ] BASE_PATH = "./input/rsna-2023-abdominal-trauma-detection" AUTOTUNE = tf.data.AUTOTUNE
config = Config()
def main(): args = sys.argv[0:] if len(args) == 1: print('Example usage:') print(' python train_model.py checkpoint_path') else: print(args) filename = args[1] print("try to load the model") loadmodel = keras.models.load_model(filename) print(loadmodel.summary())
if name == "main": main()