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

Problem in inference part #34

Open
OliviaNocentini opened this issue Feb 20, 2023 · 1 comment
Open

Problem in inference part #34

OliviaNocentini opened this issue Feb 20, 2023 · 1 comment

Comments

@OliviaNocentini
Copy link

OliviaNocentini commented Feb 20, 2023

Hello @stuarteiffert ,
thank you for your code!Really nice work! Could you help me solving the following problem? I want to do inference with a new X-train.txt that I've already and I'm trying to save the model and then restore it but i got an error with the h5 file.
Could you provide me some suggestions?

import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras.models import Sequential
from tensorflow.keras.models import save_model, load_model
from tensorflow.keras.utils import to_categorical
import numpy as np
import argparse
import cv2
import time
import os
import matplotlib
import matplotlib.pyplot as plt
from sklearn import metrics
import random
from random import randint
import tensorflow as Saver
import tensorflow.compat.v1 as tf
import tensorflow.compat.v1.train as Saver
from keras.callbacks import ModelCheckpoint
import h5py as h5




n_steps = 32

def load_X(X_path):
    file = open(X_path, 'r')
    X_ = np.array(
        [elem for elem in [
            row.split(',') for row in file
        ]], 
        dtype=np.float32
    )
    file.close()
    blocks = int(len(X_) / n_steps)
    
    X_ = np.array(np.split(X_,blocks))

    return X_


DATASET_PATH ='/home/oli/Desktop/human-pose-detection/train2/'

filepath = '/home/oli/Desktop/human-pose-detection/model.ckpt.meta'

new_model = load_model(filepath, compile = True)


X_val_path = DATASET_PATH + "X_test.txt"
 X_val = load_X(X_val_path)

predictions = new_model.predict(X_val)
 print(predictions)

Best regards,

Olivia

@stuarteiffert
Copy link
Owner

Hi Olivia, I'm not sure what's causing your problem, but if you are trying to restore a saved model maybe have a look at these issues
#5

#32

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

2 participants