title: Neural network + VGG very accurate on test images and google images but extremely poor on "real" images
body: <p>I made a model to classify dogs and cats pictures. Model was trained with transfer learning on VGG and then on a dogs and cats dataset from kaggle <a href="https://www.kaggle.com/c/dogs-vs-cats/data" rel="nofollow noreferrer">https://www.kaggle.com/c/dogs-vs-cats/data</a>.</p>
  <p>I trained it on 20,000 and then tested it on the remaining 5000 images. It was very accurate at &gt;95%. When I hand <strong>scrape</strong> some images from google that are ~20-200kb it works very well from what I can tell.</p>
  <p>But when the images are larger (thousands of pixels in height/width), like from my phone, it does horrible.</p>
  <p>Why is this happening? Is there an image processing thing that I'm missing? Or is it a learning issue? Either way, how do I fix this and make the model extendable to large images?</p>
  <p>model:</p>
  <pre><code>def get_transfer_model(self):
          model = VGG16(include_top=False, input_shape=(224, 224, 3))  # Use VGG transfer model
          for layer in model.layers:
              layer.trainable = False    # already trained
          
          added_layers = [ 
              Flatten(),
              Dense(512, activation='relu'),
              BatchNormalization(),
              Dropout(0.5),
              Dense(1, activation='sigmoid'))
          ]
          
          result = model.layers[-1].output # init result
          for layer in added_layers:
              result = layer(result)        # apply to result
              
          model = Model(inputs=model.inputs, outputs=result)
          opt = SGD(lr=0.001, momentum=0.9)
          model.compile(optimizer=opt, loss='binary_crossentropy', metrics=['accuracy'])
          return model
  </code></pre>
  <p>result calculation:</p>
  <pre><code>from keras.preprocessing.image import load_img, img_to_array
  from keras.models import load_model
  
  def result(img_path, weights_path='dogs_cats.h5'):
      img = load_img(img_path, target_size=(224, 224))
      img = img_to_array(img)
      img = img.reshape(1, 224, 244, 3) # reshape to tensor with 3 color channels
      img = img.astype('float32')
      img = img - [123.68, 116.779, 103.939] # center image to trained mean
  
      model = load_model(weights_path)
      dog = int(model.predict(img)[0][0])
      if dog:
          return 'DOG'
      return 'CAT'
  </code></pre>