I implemented the dogs vs cats code to what am working in (image classification), I followed step by step but when uploading image to get whether the image is dogs (normal) or cats (abnormal) the output doesn’t show
** [The model predicts test image data correctly but when implementing with anvil I don’t get the output]**
Code Sample:
test_img = test_img.resize((W,H), resample=PIL.Image.BICUBIC)
test_arr = img_to_array(test_img)
test_arr = np.expand_dims(test_arr, axis=0)
test_arr /= 255.0
plt.imshow(test_img)
score = model.predict(test_arr)
label = np.argmax(score,axis=1)
print(score)
if label < 0.5:
print(“Abnormal”)
else:
print(“Normal”)
import anvil.server
anvil.server.connect(" …")
import anvil.media
@anvil.server.callable
def classify_image(file):
with anvil.media.TempFile(file) as filename:
img = load_img(filename)
img = img.resize((W,H), resample=PIL.image.BICUBIC)
arr = img_to_array(img)
arr = np.expand_dims(arr, axis=0)
arr /= 255.0
score= model.predict(arr)
label = np.argmax(score,axis=1)
return score, "abnormal" if label < 0.5 else "normal"
# this is a formatted code snippet.
# paste your code between ```
Clone link:
https://anvil.works/build#clone:GIIU6ARLGU4OM6SC=253NAI3JJR2EOQVOLSG4VGII