Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output is always 1 #2

Closed
freedom9393 opened this issue Feb 16, 2021 · 1 comment
Closed

Output is always 1 #2

freedom9393 opened this issue Feb 16, 2021 · 1 comment
Labels
question Further information is requested

Comments

@freedom9393
Copy link

freedom9393 commented Feb 16, 2021

I'm running the following code to test my custom images, and here is the cude:

import tensorflow as tf
from utils import Dataset, plotImages, plotWrongImages
from models import EfficientCapsNet
import cv2, numpy as np

img_path = "imgs/box_9.jpg"
img_np = cv2.bitwise_not(cv2.imread(img_path, 0)) # invert conversion

gpus = tf.config.experimental.list_physical_devices('GPU')
tf.config.experimental.set_visible_devices(gpus[0], 'GPU')
tf.config.experimental.set_memory_growth(gpus[0], True)

# some parameters
model_name = 'MULTIMNIST'
custom_path = None # if you've trained a new model, insert here the full graph weights path

dataset = Dataset(model_name, config_path='config.json')

model_test = EfficientCapsNet(model_name, mode='test', verbose=True, custom_path=custom_path)

model_test.load_graph_weights() # load graph weights (bin folder)

model_test.evaluate(dataset.X_test, dataset.y_test) # if "smallnorb" use X_test_patch

#not working with MultiMNIST

shape = dataset.X_test[0].shape

img_np = cv2.resize(img_np, shape[:2], interpolation=cv2.INTER_AREA)
img_np = img_np[..., None]

y_pred = model_test.predict(np.expand_dims(img_np, axis=0))[0] # if "smallnorb" use X_test_patch

print(np.argmax(y_pred))
print(y_pred)

cv2.imshow('show', img_np)
cv2.waitKey(0)

And here is the result:

[[0.3153154  0.956559   0.2567287  0.2726928  0.18593171 0.6188526
  0.14006346 0.44058013 0.36337793 0.15720315]]

As it's shown, index 1 has highest value and it means the output is 1. But I tested 13 images and all has highest value in index 1 (output is always 1). What am I doing wrong?

@fsalv
Copy link
Collaborator

fsalv commented Feb 16, 2021

How are your test images generated? You are using the model trained on the MultiMNIST dataset, that is expecting two MNIST images superimposed and has been trained in order to dect both of them. If you have classical digit images, set

model_name = 'MNIST'

@EscVM EscVM closed this as completed Feb 17, 2021
@EscVM EscVM added the question Further information is requested label May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants