0

I'm working on ActionAI(https://github.com/smellslikeml/ActionAI) which is a python library that classifies human actions.
I got this error running iva.py, the final script.

...
if RUNSECONDARY:
    import tensorflow as tf
    secondary_model = tf.keras.models.load_model('models/classifier.sav')
    window = 3
    pose_vec_dim = 36
    motion_dict = {0: 'lying', 1: 'sit', 2: 'stand', 3: 'walk'}
...
2021-11-16 21:53:39.382516: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.0
Traceback (most recent call last):
  File "iva.py", line 256, in <module>
    secondary_model = tf.keras.models.load_model('models/classifier.sav')
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/saving/save.py", line 149, in load_model
    loader_impl.parse_saved_model(filepath)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/saved_model/loader_impl.py", line 83, in parse_saved_model
    constants.SAVED_MODEL_FILENAME_PB))
OSError: SavedModel file does not exist at: models/classifier.sav/{saved_model.pbtxt|saved_model.pb}

In models directory, classifier.sav is existing but empty and doesn't have pbtxt or pb.

This is train.py

import pandas as pd
from sklearn.pipeline import Pipeline

from transformer import PoseExtractor

def actionModel(classifier):
    pipeline = Pipeline([
               ('pose_extractor', PoseExtractor()),
               ('classifier', classifier)])
    return pipeline

def trainModel(csv_path, pipeline):
    df = pd.read_csv(csv_path)
    X = df['image'].values
    y = df['label']
    pipeline = pipeline.fit(X, y)
    return pipeline.get_params()['steps'][1][1]  

if __name__ == '__main__':
    import pickle
    import argparse
    import importlib

    parser = argparse.ArgumentParser(description='Train pose classifier')
    parser.add_argument('--config', type=str, default='conf',
                        help="name of config .py file inside config/ directory, default: 'conf'")
    args = parser.parse_args()
    config = importlib.import_module('config.' + args.config)

    pipeline = actionModel(config.classifier())
    model = trainModel(config.csv_path, pipeline)

    # Dump the model to file
    pickle.dump(model, open(config.classifier_model, 'wb'), protocol=2)

I think pickle.dump(model, open(config.classifier_model, 'wb'), protocol=2) in train.py doesn't work properly.
I've tried changing the filename extension to pkl, h5, and pb but didn't work.
sudo apt install python3-h5py this command also changed nothing.

hds
  • 1
  • 1

1 Answers1

0

pickle.dump() should take open() as a second argument, i.e.:

import pickle

filename = 'your_pickle_filename.pkl'
pickle.dump(model, open(filename, 'wb'))
Niqua
  • 386
  • 2
  • 15
  • Thanks for the answer! ```open()``` is already a second argument and I did as you told but the results were the same. – hds Dec 27 '21 at 12:16