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

tensorflow (Python 3.7) h5 model not loading #24

Closed
voqueric opened this issue Jun 18, 2019 · 6 comments
Closed

tensorflow (Python 3.7) h5 model not loading #24

voqueric opened this issue Jun 18, 2019 · 6 comments

Comments

@voqueric
Copy link

Package name: tensorflow
Link to piwheels page: https://www.piwheels.org/project/tensorflow
Version: 1.13.0
Python version: 3.7.3
More information: Downloaded, compiled, installed separate from OS package manager on Raspbian Stretch using RPI0W

Prior to recent tensorflow 1.13.0 package update the dependencies were:

h5py==2.9.0
Keras-Applications==1.0.7
Keras-Preprocessing==1.0.9
tensorboard==1.13.1
tensorflow==1.13.1
tensorflow-estimator==1.13.0

After the update the dependencies are:

h5py==2.9.0
Keras-Applications==1.0.8
Keras-Preprocessing==1.1.0
tensorboard==1.13.1
tensorflow==1.13.1
tensorflow-estimator==1.14.0rc1

I build an h5 model file using tensorflow 1.13.0 on a PC running AMD64 Kubuntu 18.04 and a separately downloaded, compiled, installed Python 3.7.3, dependencies are same as second list (above):

import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.callbacks import Callback, ModelCheckpoint
from tensorflow.keras import optimizers as ko

    class EarlyStoppingByVal(Callback):
        def __init__(self, monitor='loss', value=0.0001, verbose=0):
            super(Callback, self).__init__()
            self.monitor = monitor
            self.value = value
            self.verbose = verbose

        def on_epoch_end(self, epoch, logs={}):
            current = logs.get(self.monitor)
            if current is None:
                print("Early stopping requires %s available!" % self.monitor, RuntimeWarning)

            if self.monitor == 'loss':
                if current < self.value:
                    if self.verbose > 0:
                        print("Epoch %05d: early stopping THR" % epoch)
                    self.model.stop_training = True

            if self.monitor == 'acc':
                if current >= self.value:
                    if self.verbose > 0:
                        print("Epoch %05d: early stopping THR" % epoch)
                    self.model.stop_training = True

    model = keras.Sequential([
        keras.layers.Flatten(
            input_shape=(train_data.shape[1], train_data.shape[2])
        ),
        keras.layers.Dense(
            250,
            activation=tf.nn.relu
        ),
        keras.layers.Dense(
            500,
            activation=tf.nn.relu
        ),
        keras.layers.Dense(
            1000,
            activation=tf.nn.relu
        ),
        keras.layers.Dense(
            500,
            activation=tf.nn.relu
        ),
        keras.layers.Dense(
            250,
            activation=tf.nn.relu
        ),
        keras.layers.Dense(
            250,
            activation=tf.nn.softmax
        )
    ])

    model.compile(
        optimizer=ko.Adamax(),
        loss='sparse_categorical_crossentropy',
        metrics=['accuracy']
    )

    model.fit(
        train_data,
        train_labels,
        epochs=150,
        shuffle=True,
        verbose=1,
        callbacks=callbacks
    )
    model.summary()
    model.save(train_mdl_file)

At this point the model is transferred to RPI0W and the following code is executed with tensorflow 1.13.0 also using the dependencies in the second list:

import tensorflow as tf

    tf_mdl = tf.keras.models.load_model(data_url_dict['mdl'])
    tf_preds = tf_mdl.predict(x=img_data_np)

The RPI0W returns the following warnings/errors:

WARNING: Logging before flag parsing goes to stderr.
W0618 13:47:20.288138 3069616128 deprecation_wrapper.py:118] From /usr/local/opt/python-3.7.3/lib/python3.7/site-packages/tensorflow/__init__.py:98: The name tf.AUTO_REUSE is deprecated. Please use tf.compat.v1.AUTO_REUSE instead.

W0618 13:47:20.295286 3069616128 deprecation_wrapper.py:118] From /usr/local/opt/python-3.7.3/lib/python3.7/site-packages/tensorflow/__init__.py:98: The name tf.AttrValue is deprecated. Please use tf.compat.v1.AttrValue instead.

W0618 13:47:20.300013 3069616128 deprecation_wrapper.py:118] From /usr/local/opt/python-3.7.3/lib/python3.7/site-packages/tensorflow/__init__.py:98: The name tf.COMPILER_VERSION is deprecated. Please use tf.version.COMPILER_VERSION instead.

W0618 13:47:20.304398 3069616128 deprecation_wrapper.py:118] From /usr/local/opt/python-3.7.3/lib/python3.7/site-packages/tensorflow/__init__.py:98: The name tf.CXX11_ABI_FLAG is deprecated. Please use tf.sysconfig.CXX11_ABI_FLAG instead.

W0618 13:47:20.309751 3069616128 deprecation_wrapper.py:118] From /usr/local/opt/python-3.7.3/lib/python3.7/site-packages/tensorflow/__init__.py:98: The name tf.ConditionalAccumulator is deprecated. Please use tf.compat.v1.ConditionalAccumulator instead.

SavedModel file does not exist at: /path/to/model/model.h5/{saved_model.pbtxt|saved_model.pb}

When I attempt to load the model on the PC using the same code, no errors are returned and predictions take place. Based on this outcome I am assuming that there is something different in the cp37 packages built for AMD64 and ARM, but unsure if it is the tensorflow package itself or one of its dependencies.

@bennuttall
Copy link
Member

This is an upstream issue. Ping @petewarden

@bennuttall bennuttall transferred this issue from piwheels/piwheels Jul 13, 2019
@leematthewshome
Copy link

I have just built a new image on Raspbian (RPI3B+) and installed tensorflow from tensorflow-1.13.1-cp37-none-linux-armv71.whl.

I am getting exactly the same errors about deprecated names when I import tensor flow into python3.7.

@leematthewshome
Copy link

Errr, sorry but what do you mean by "This is an upstream issue"?

@bennuttall
Copy link
Member

"upstream" means the maintainer. File an issue with them: https://github.com/tensorflow/tensorflow/issues

@leematthewshome
Copy link

got it. thanks. I am finding that my model loads but python regularly locks up while processing.

thanks

@bennuttall
Copy link
Member

Ok, it's just not something we can fix here. It's an issue with the source code of the package itself, not the piwheels project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants