<blockquote>
  <p>But when I am predicting it for house.jpg or laptop.jpg or images
  other than these 3-classes then also it predicting among these
  3-classes.</p>
</blockquote>

<p>This is the normal behaviour because neural network in the last layer</p>

<pre><code>model.add(Dense(3, activation="softmax"))
</code></pre>

<p>it returns <em>probabilities</em> for every class from your problem.</p>

<p>So, if you're using a <code>laptop.jpg</code> image maybe it returns three small probabilities and the biggest one it gives the output for you.</p>

<p>Since you're not using <code>laptop</code> images in your <code>training</code> set, then <code>neural network</code> has no ideea about it.</p>

<p>One approach could be setting a threshold probability, let's say <code>50%</code> and if no one from those <code>3</code> probabilities exceeds this threshold, then print <code>Unknown</code>.</p>

<p>With other words, if you are using a <em>softmax</em> distribution for your classification, then you could determine what your baseline <em>max</em> <code>probability</code> is for correctly classified samples, and then infer if a new sample doesn't belong to any of your known classes if its <em>max probability</em> is below some kind of <code>threshold</code>.</p>

<p>This idea comes from a <em>research</em> paper which explains this situation: <a href="https://arxiv.org/abs/1610.02136" rel="nofollow noreferrer">A Baseline for Detecting Misclassified and Out-of-Distribution Examples in Neural Networks</a></p>
Deep learning and neural network
<pre><code># set the matplotlib backend so figures can be saved in the background
import matplotlib
matplotlib.use("Agg")

# import the necessary packages
from keras.layers.core import Dropout, Activation
from sklearn.preprocessing import LabelBinarizer
from sklearn.model_selection import train_test_split
from keras.models import Sequential
from keras.optimizers import SGD
import matplotlib.pyplot as plt

from keras.callbacks import EarlyStopping
from keras.callbacks import ModelCheckpoint
from keras.layers import Dense, Conv2D, Flatten
from keras.layers.convolutional import MaxPooling2D

(trainX, testX, trainY, testY) = train_test_split(data,labels, test_size=0.25, random_state=42)

lb = LabelBinarizer()
trainY = lb.fit_transform(trainY)
testY = lb.transform(testY)

#create model
model = Sequential()
#add model layers
model.add(Conv2D(32, kernel_size=3, activation="relu", input_shape=(32,32,3)))
model.add(MaxPooling2D(pool_size=(2,2)))

model.add(Conv2D(32, kernel_size=3, activation="relu"))
model.add(MaxPooling2D(pool_size=(2,2)))

model.add(Conv2D(64, kernel_size=3, activation="relu"))
model.add(MaxPooling2D(pool_size=(2,2)))

model.add(Flatten())
model.add(Dense(64))
model.add(Activation("relu"))
model.add(Dropout(0.5))
model.add(Dense(3, activation="softmax"))

# initialize our initial learning rate and # of epochs to train for
INIT_LR = 0.001
EPOCHS = 500

opt = SGD(lr=INIT_LR, clipvalue=0.5)
model.compile(loss="categorical_crossentropy", optimizer=opt,metrics=["accuracy"])

es = EarlyStopping(monitor='val_loss', mode='min', verbose=1, patience=200)
mc = ModelCheckpoint('best_model_500Epoch.h5', monitor='val_accuracy', mode='max', verbose=1, save_best_only=True)

H = model.fit(trainX, trainY, validation_data=(testX, testY),epochs=EPOCHS, batch_size=32,callbacks=[es, mc])
</code></pre>

<p>Using following script for prediction.</p>

<pre><code>from keras.models import load_model
import pickle
import cv2
import os
import matplotlib.pyplot as plt
from keras import backend as k


new_model = load_model('model_name.h5')
lb = pickle.loads(open("Label_Binarizer", "rb").read())

dirName = "Other_than_class"
listOfFile = os.listdir(dirName)



# Iterate over all the entries
for entry in listOfFile:
    # Create full path
    fullPath = os.path.join(dirName, entry)
    # If entry is a directory then get the list of files in this 
    directory
    image = cv2.imread(fullPath)
    output = image.copy()
    image = cv2.resize(image, (32, 32))

    # scale the pixel values to [0, 1]
    image = image.astype("float") / 255.0

    # check to see if we should flatten the image and add a batch
    # dimension
    image = image.flatten()
    image = image.reshape((1, image.shape[0]))


    # preds = new_model.predict(image)
    preds = new_model.predict(image.reshape(1, 32, 32, 3))
    print(preds[0])

    k.clear_session()

    # find the class label index with the largest corresponding 
    probability
    i = preds.argmax(axis=1)[0]
    label = lb.classes_[i]


    plt.grid(False)
    plt.imshow(output)
    plt.xlabel("Actual: " + str(entry))
    plt.title("Prediction: " + str(preds[0][i] * 100)+"  "+str(label))
    plt.show()
</code></pre>

<p>I have developed model using above architecture for 3-classes cat,dog and flower. it giving good result when i am predicting any unseen image of these classes. but when I am predicting it for house.jpg or laptop.jpg or images other than these 3-classes then also it predicting among these 3-classes which is so disgusting.
what's i am doing wrong?</p>

<p>The accuracy of predicting of house.jpg or laptop.jpg is also above 85%.
what to do so that it must not predict images out of the classes.</p>