0

I have a CNN trained on classes = [dog, cat, frog] and in the testing-phase-only, I want to include several pictures of horses to see which known classes those images get classified as. Any idea how to implement this in a Keras model?

One thing I've tried, but I don't like is to distribute the horse pictures equally and randomly across the training images for the known classes (dog, cat, and frog) and then see what happens with the testing images. I'm worried the number of horse images (though relatively small) would negatively impact the model's knowledge of a Here is the corresponding code:

<x_train, x_test, y_train, and y_test has already been done prior to this step>

clsLst = [dog, cat, frog]
clsRemove = horse

seed(1)
newClsLst = [0,0,0]
for I in range(0,len(y_train)):
  if y_train[i][clsRemove] = 1.0:
    y_train[i][clsRemove] = 0.0
    randIndex = random.randint(0,8)
    newCls = clsLst[randIndex]
    newClsLst[newCls] = newClsLst[newCls] + 1
    y_train[i][newCls] = 1.0

This is only my second time using Keras and I don't have a programming background so all tips and overexplaining is appreciated.

Kara Combs
  • 73
  • 1
  • 1
  • 8

1 Answers1

1

As you have correctly noted yourself, adding the horse images to your training data is a bad idea - unless, of course, you want to expand your model's classification capabilities so that it learns to identify horses.

That said, you could simply add the horse images to x_test or set up a separate testing dataset (say, x_test_horses) for this specific testing purpose, i.e. what horses are (mis)classified as. As has been pointed out in Saankhya Mondal's comment below your original post, with both options you can simply use model.predict() to make predictions (y_pred = model.predict(x_test) respectively y_pred = model.predict(x_test_horses)).

Georgy Kopshteyn
  • 678
  • 3
  • 13
  • I would like to eventually have the model identify horses. Thank you for the very straightforward and kind answer. – Kara Combs Jun 08 '21 at 17:46
  • @KaraCombs if you would like your model to identify horses, I think you should simply append the horse data to your dataset before the train-test split and then shuffle it. To shuffle the dataframe, you could do: `df = df.sample(frac=1).reset_index(drop=True)` (see [here](https://stackoverflow.com/questions/29576430/shuffle-dataframe-rows)). – Georgy Kopshteyn Jun 08 '21 at 18:12