Skip to content

Conversation

@Chetabahana
Copy link
Collaborator

@Chetabahana Chetabahana commented Jul 24, 2021

Summary

Main Code: predict.py

# Defiine params and lib
import requests
from io import BytesIO

from PIL import Image
import numpy as np

# Parameters
input_size = (150,150)

#define input shape
channel = (3,)
input_shape = input_size + channel

#define labels
labels = ['daisy', 'dandelion', 'rose', 'sunflower', 'tulip']

# # Define preprocess function
def preprocess(img,input_size):
    nimg = img.convert('RGB').resize(input_size, resample= 0)
    img_arr = (np.array(nimg))/255
    return img_arr

def reshape(imgs_arr):
    return np.stack(imgs_arr, axis=0)


# # Load models
from tensorflow.keras.models import load_model

# ada 2 cara load model, jika cara pertama berhasil maka bisa lasngusng di lanjutkan ke fungsi prediksi
MODEL_PATH = 'model/medium_project/model.h5'
model = load_model(MODEL_PATH,compile=False)

# # Predict the image
# read image
im = Image.open('contoh_prediksi.jpg')
X = preprocess(im,input_size)
X = reshape([X])
y = model.predict(X)

print( labels[np.argmax(y)], np.max(y) )
print( labels[np.argmax(y)], np.max(y) )

# read image
im = Image.open('dataset/train/dandelion/2522454811_f87af57d8b.jpg')
X = preprocess(im,input_size)
X = reshape([X])
y = model.predict(X)

print( labels[np.argmax(y)], np.max(y) )
![model](https://user-images.githubusercontent.com/36441664/126858435-caa1dfd1-319c-4b74-a7c8-f44317a4bed1.png)

Checklist

  1. Privileged views and APIs are guarded by proper permission checks.
  2. All visible strings are translated with proper context.
  3. All data-formatting is locale-aware (dates, numbers, and so on).
  4. Database queries are optimized and the number of queries is constant.
  5. Database migration files are up to date.
  6. The changes are tested.
  7. The code is documented (docstrings, project documentation).
  8. GraphQL schema and type definitions are up to date.
  9. Changes are mentioned in the changelog.

Reference

Screenshots

output_SNyZ1WhJMVLm_0

reshape-bad2

2021-07-24 (37)
contoh_prediksi
2021-07-25 (2)
Untitled

model
2021-07-25 (1)
2021-07-25
Untitled
2021-07-25 (3)
Untitled
2021-07-25 (16)

2021-07-25 (5)
0_V8WR6RyzJrRO_b9m
Untitled
2021-07-25 (17)
2021-07-25 (17)
2021-07-26 (7)
Untitled
2021-07-26 (14)
2021-07-27 (2)
Untitled
Untitled
2021-07-27 (5)
2021-07-27 (4)
sfc-scannow-offline-scan-windows10
3D-Brain
Save-and-Load-Your-Keras-Deep-Learning-Models

@Chetabahana Chetabahana merged commit 1a9bb45 into Chetabahana Jul 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants