Comments (6)
@fjmsouza, thank you for sharing the solution!
from two-branch-plant-disease.
Hi @fjmsouza,
I think that you might have the same problem as reported here:
joaopauloschuler/two-path-noise-lab-plant-disease#1
The two-path images are loaded with:
train_x, val_x, test_x, train_y, val_y, test_y, classweight, classes = cai.datasets.load_images_from_folders(seed=7, root_dir=data_dir, lab=True,
verbose=Verbose, bipolar=False, base_model_name='plant_leaf',
training_size=0.6, validation_size=0.2, test_size=0.2,
target_size=(input_shape[0],input_shape[1]),
has_training=True, has_validation=True, has_testing=True,
smart_resize=True)
So, for your prediction to work, you'll need to use the same image transformations:
- RGB to LAB.
- Bipolar = False (numbers are positive).
- smart_resize = True.
I would expect values on each LAB channel to be similar to:
Channel 0 min: 0.0 max: 1.0
Channel 1 min: 0.20254138 max: 0.899006
Channel 2 min: 0.24579802 max: 0.94360983
You may look at the source code of cai.datasets.load_images_from_folders
and check what transformations you would need.
from two-branch-plant-disease.
Calling the function cai.datasets.load_images_from_files
will probably solve the problem:
def load_images_from_files(file_names, target_size=(224,224), dtype='float32', smart_resize=False, lab=False, rescale=False, bipolar=False):
"""Creates an array with images from an array with file names.
# Arguments
file_names: array with file names.
target_size: output image size.
dtype: output type.
smart_resize: indicates if aspec ration should be kept adding padding.
lab: indicates if LAB color encoding should be used.
"""
from two-branch-plant-disease.
Just fixed the comments on the source code: joaopauloschuler/k-neural-api@162f83a.
This is the updated version:
def add_padding_to_make_img_array_squared(img):
""" Adds padding to make the image squared.
# Arguments
img: an image as an array.
"""
def load_images_from_files(file_names, target_size=(224,224), dtype='float32', smart_resize=False, lab=False, rescale=False, bipolar=False):
"""Creates an array with images from an array with file names.
# Arguments
file_names: array with file names.
target_size: output image size.
dtype: output type.
smart_resize: indicates if aspect ratio should be kept via padding.
lab: indicates if LAB color encoding should be used.
from two-branch-plant-disease.
Ok, I'm applying your tips, for while...
Would be something like this:
import numpy as np
from google.colab import files
import keras.utils as image
uploaded = files.upload()
for fn in uploaded.keys():
path = '/content/' + fn
img = cai.datasets.load_images_from_files(file_names=path)
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
images = np.vstack([x])
classes = model.predict(images, batch_size=10)
?
and, for while:
searching for a solution, but your help would be welcome
from two-branch-plant-disease.
I think that we'll work around with the similar tip in #issue
Running this:
# Here's a codeblock just for fun. You should be able to upload an image here
# and have it classified without crashing
import numpy as np
from google.colab import files
import keras.utils as image
import cv2
model = tensorflow.keras.models.load_model('/content/two-path-inception-v2.8-False-0.2-best_result.hdf5',custom_objects={'CopyChannels': cai.layers.CopyChannels})
uploaded = files.upload()
for fn in uploaded.keys():
# predicting images
path = '/content/' + fn
imgs = cv2.imread(path)
imgs = cv2.cvtColor(imgs, cv2.COLOR_BGR2RGB)
imgs = cv2.cvtColor(imgs, cv2.COLOR_RGB2LAB)
imgs=cv2.resize(imgs, (128,128))
imm_array=np.array(imgs)
imm_array=imm_array/255
imm_array=imm_array.reshape(1, 128, 128, 3)
predictions = model.predict(imm_array)
prediction_score = tf.nn.softmax(predictions)
predicated_class = np.argmax(prediction_score)
print(
"This image most likely belongs to {} with a {:.2f} percent confidence."
.format(classes[predicated_class], 100 * np.max(prediction_score)))
Thank you!
from two-branch-plant-disease.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from two-branch-plant-disease.