How to use your trained model - Deep Learning basics with Python, TensorFlow and Keras p.6
Why Stack Overflow recommends it
Stack Overflow users cite it as the tutorial they were following when their own predict or image-preparation code threw errors, or when they wanted to extend the cat/dog classifier.
Recommended by 0 people across 0 different months, 2019 to 2020.
What it is
Part 6 of sentdex's Deep Learning basics series with Python, TensorFlow and Keras. It shows how to load a trained cats vs dogs CNN, preprocess a new image with OpenCV, and call predict to classify it.
What people said
Cites Iyad Alsulaiman · 2019-07 · Stack Overflow · on “OpenCV(4.1.0) error: (-215:Assertion failed)”
I am following this tutorial series: [this video] When I try to use the model outside the program by prediction it gives me the following error: error: OpenCV(4.1.0) /Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/resize.cpp:3718: error: (-215:Assertion failed) !ssize.empty() in function 'resize' Below the code when loading the model: import cv2 import tensorflow as tf CATEGORIES = ["Dog", "Cat"] import cv2 import tensorflow as tf CATEGORIES = ["Dog", "Cat"] def prepare(filepath): IMG_SIZE = 50 img_array = cv2.imread(filepath, cv2.IMREAD_GRAYSCALE) #return img_array.reshape(-1, IMG_SIZE, IMG_SIZE, 1) new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE)) return new_array.resh
Cites yosi · 2019-09 · Stack Overflow · on “can i mark the dog with this model?”
I saw this code on the youtube How to use your trained model - Deep Learning basics with Python, TensorFlow and Keras p.6 [this video] If I bring a picture, he tells me if the picture is cat or dog. I can use this code and mark the dog/cat in the picture? Or do I need to run a brand-new model? in the code I get all pic of dog and cat and put it in X and y X = it's the features y = it the label the code dense_layers = [0] layer_sizes = [64] conv_layers = [3] model = Sequential() model.add(Conv2D(layer_size, (3, 3), input_shape=X.shape[1:])) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Conv2D(layer_size, (3, 3))) model.add(Activation('relu')) model.add(MaxPoolin
Cites Kim404 · 2020-05 · Stack Overflow · on “ValueError: Error when checking input: expected conv2d_input to have 4 dimensions, but got array with shape (None, 1)”
I finish trained my model that consist of 20 classes and reach 0.9993 accuracy and currently working for testing. I'm following this tutorial [this video] but im getting error at prediction = model.predict(['test1.jpg']) The training data is defined as for features, label in training_data: x.append(features) y.append(label) x = np.array(x).reshape(-1, IMG_SIZE, IMG_SIZE,1) and this is my definition for cnn x = pickle.load(open("x.pickle", "rb" )) y = pickle.load(open("y.pickle", "rb")) x = x/255.0 model = Sequential() model.add(Conv2D(64,(3,3), input_shape = x.shape[1:IMG_SIZE])) model.add(Activation("relu")) model.add(MaxPool2D(pool_size=(2,2))) model.add(Conv2D(64,(3,3), input_shape = x.shape[1