Beispiel #1
0
# testing
print ('testing ........')
def load_image(img_path, show=False):
    print("---" + img_path)
    img = image.load_img(img_path, target_size=(224, 224))
    img_tensor = image.img_to_array(img)                    # (height, width, channels)
    img_tensor = np.expand_dims(img_tensor, axis=0)         # (1, height, width, channels), add a dimension because the model expects this shape: (batch_size, height, width, channels)
    img_tensor /= 255.                                      # imshow expects values in the range [0, 1]
    if show:
        plt.imshow(img_tensor[0])
        plt.axis('off')
        plt.show()
    return img_tensor
model.load_weights(DATASET_DIR+'/avoidance.h5')
import random, os
random.seed()
random_filename = random.choice([
    x for x in os.listdir(DATASET_DIR+"/testing")
    if os.path.isfile(os.path.join(DATASET_DIR+"/testing", x)) and x.endswith('.jpg')
])
print(random_filename)
preprocessed_image = load_image(os.path.join(DATASET_DIR+"/testing", random_filename),True)
predictions = model.predict(preprocessed_image)
print(predictions)