Git Product home page Git Product logo

Comments (13)

pierluigiferrari avatar pierluigiferrari commented on May 24, 2024
  1. Load the image.
  2. Expand the first dimension since model.predict() requires 4-D input: imgs = np.array([img])
  3. Call model.predict(imgs)

from ssd_keras.

ecophy avatar ecophy commented on May 24, 2024

Thanks a lot for your kind help ^_^ I followed your suggestion and revised your code as below ("Revised code"). In the end I get an image "grey-colored" with blue boxes (instead of the original image which is NOT grey-colored). Can you help me to correct the revised code below? I really appreciate your kind attention and warm help!

#Revised code:

#Generate a sample
import cv2
import numpy as np

i000=Image.open('...\001.jpg')
i000.load()
i000=np.asarray(i000,dtype="float32")
X=[] # List of Images
X.append(i000)
X=np.asarray(X,dtype="float32")
i=0

#Make a prediction
y_pred = model.predict(X)
...
(The same code with [97]-[99] in train_ssd300.ipynb)

from ssd_keras.

pierluigiferrari avatar pierluigiferrari commented on May 24, 2024

As of the latest commit it is now also possible to use BatchGenerator to serve batches of images only (no labels).

You can do this either by passing the constructor a text file that contains the names (just the base names, not the full file paths) of the images you would like to generate:

generator = BatchGenerator(filenames='list_of_your_image_names.txt',
                           filenames_type='text',
                           images_path='path_to_directory/that_contains_the_images')

Or you could just pass a Python list that contains the full file paths of the images you would like to generate:

generator = BatchGenerator(filenames=python_list_of_your_image_paths)

Then call generator.generate() with the desired options (it must be train=False). Note that the generator returns two lists in this case, the batch of images, and a list of the names of the images in the batch.

from ssd_keras.

ecophy avatar ecophy commented on May 24, 2024

Thanks a lot for your kind help ^_^ I followed your suggestion and revised your code as below ("Revised code"). Then, I get an error message "AttributeError: 'numpy.ndarray' object has no attribute 'read' ". Can you help me to correct the revised code below? I really appreciate your kind attention and warm help!

#Revised code:
#Generate a sample
import cv2
import numpy as np

i000=Image.open('...\001.jpg')
i000.load()
i000=np.asarray(i000,dtype="float32")
l000=[] # List of Images
l000.append(i000)
g000 = BatchGenerator(filenames=l000)
g001 = g000.generate(batch_size=1,...,diagnostics=False)
X, filenames = next(g001) # <= I get an error message here
i = 0

#Make a prediction
y_pred = model.predict(X)
...
(The same code with [97]-[99] in train_ssd300.ipynb)

from ssd_keras.

pierluigiferrari avatar pierluigiferrari commented on May 24, 2024

As described in my post above, the list you pass to the constructor must contain the paths to the images, not the images themselves, i.e. your list should be

l000.append('...\001.jpg')

The batch generator loads the images for you, you only give it the paths where to find those images.

from ssd_keras.

ecophy avatar ecophy commented on May 24, 2024

Thanks a lot for your kind help ^_^ I am following your suggestion and two values of the predicted boxes are infinite with the error message below (The loss is 317 at this point and I continue to retrain the model). Is it because of huge loss or other problem(s)? I really appreciate your continued support!

#Error message:
Predicted boxes:
[[ 1.00e+00 1.00e+00 -inf inf 3.18e+09 3.18e+09]]
...\Anaconda3\lib\site-packages\spyder\utils\ipython\start_kernel.py:400: RuntimeWarning: overflow encountered in exp
...\Anaconda3\lib\site-packages\spyder\utils\ipython\start_kernel.py:65: RuntimeWarning: invalid value encountered in multiply
spy_cfg.InteractiveShell.xmode = 'Plain'
...\Anaconda3\lib\site-packages\spyder\utils\ipython\start_kernel.py:66: RuntimeWarning: invalid value encountered in multiply
...\Anaconda3\lib\site-packages\spyder\utils\ipython\start_kernel.py:229: RuntimeWarning: invalid value encountered in less_equal

from ssd_keras.

TanmoyDL avatar TanmoyDL commented on May 24, 2024

I got the error like " expected input_1 to have 4 dimensions, but got array with shape (687, 1087, 3)" while passing a image into model.predict([image]).
images = cv2.imread('./examples/pred_01.png')
image = np.array(images)
#Y_pred = model.predict([images])
#Y_pred = model.predict([image])
I have tried both the ways but I got the same error as mentioned the above.
I am waiting for your valuable suggestions.

from ssd_keras.

pierluigiferrari avatar pierluigiferrari commented on May 24, 2024

@TanmoyDL apparently the input to model.predict() needs to be an array, so the way to do it is

image = cv2.imread('./examples/pred_01.png')
y_pred = model.predict(np.array([image]))

@ecophy if the loss is 317 then something is likely very wrong and there is no point trying to make any predictions with such a model, but with the provided information I can't tell anything more specific since I know nothing about how you trained the model, on what data, etc.

from ssd_keras.

TanmoyDL avatar TanmoyDL commented on May 24, 2024

@pierluigiferrari Thanks for your kind help. It is working fine.
Now, I will test it on the video data by passing the video frames into model.predict (). I hope it should work.

from ssd_keras.

ecophy avatar ecophy commented on May 24, 2024

Thanks a lot for your kind help ^_^ I rebuilt the data, retrained the model then the prediction worked well :) Please, have a nice day!

from ssd_keras.

stale avatar stale commented on May 24, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from ssd_keras.

SahadevPoudel avatar SahadevPoudel commented on May 24, 2024

@pierluigiferrari Thanks for your kind help. It is working fine.
Now, I will test it on the video data by passing the video frames into model.predict (). I hope it should work.

Did you test on video data?

from ssd_keras.

Alex1101a avatar Alex1101a commented on May 24, 2024

@SahadevPoudel did you manage to detect on a video?
if so are you willing to share your code?
i got stuck and tried for several days now and would appreciate any help or hint from you :)

from ssd_keras.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.