0

I just make a prediction result like this, but right now I want to save it in .json format

import keras
from keras.models import load_model
from keras.preprocessing import image
import json
import numpy as np

filepath = 'model2.h5'
test_img = 'falling14145853.png'
model = keras.models.load_model(filepath)

img = image.load_img(test_img, target_size=(150, 150))

x = image.img_to_array(img)
x = np.expand_dims(x, axis = 0)

images = np.vstack([x])
classes = model.predict(images, batch_size = 10)

print(test_img)
print(classes)

output

falling14145853.png

[[1. 0. 0.]]

Angie
  • 1
  • 3
  • 1
    not sure if the output is numpy array or tf tensor but you can convert tensor to numpy with `numpy()` method and then you can refer to this thread: https://stackoverflow.com/questions/26646362/numpy-array-is-not-json-serializable – Dominik Ficek Jul 07 '21 at 21:22

0 Answers0