Comments (13)
- Load the image.
- Expand the first dimension since
model.predict()
requires 4-D input:imgs = np.array([img])
- Call
model.predict(imgs)
from ssd_keras.
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.
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.
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.
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.
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.
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.
@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.
@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.
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.
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.
@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.
@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)
- InvalidArgumentError when compiling model with ssd_loss HOT 1
- WARNING:tensorflow:Gradients do not exist for variables ['conv4_3/bias:0',...] when minimizing the loss. HOT 1
- "Invalid argument: Index out of range using input dim 0; input has only 0 dims" during ssd300 model training
- load weight
- ValueError: Error when checking input: expected input_3 to have 4 dimensions, but got array with shape
- While training I got training terminate error . Epoch 00001: LearningRateScheduler setting learning rate to 0.001. 1/10 [==>...........................] - ETA: 4:08 - loss: nanBatch 0: Invalid loss, terminating training Epoch 00001: saving model to ssd512_URPC2018_epoch-01.h5 Process finished with exit code 0
- ValueError: An operation has `None` for gradient. Please make sure that all of your ops have a gradient defined (i.e. are differentiable). Common ops without gradient: K.argmax, K.round, K.eval.
- ValueError: Layer model expects 1 input(s), but it received 2 input tensors. Inputs received: [<tf.Tensor 'IteratorGetNext:0' shape=(None, None, None, None) dtype=uint8>, <tf.Tensor 'IteratorGetNext:1' shape=(None, None, None) dtype=float32>] HOT 23
- Parameters of the model HOT 1
- Bouding boxes predictions are concentrated in left top corner HOT 1
- Ambiguous dimension while trying to load weights.
- Urgent!! Invalid Loss HOT 4
- What are the requirements to run this code?. HOT 1
- Pascal VOC Training Person Detection
- The device being used is CPU while capturing image from webcam. How do I use my GPU for processing instead?
- Label error during Coco Training HOT 1
- TypeError: Expected any non-tensor type, got a tensor instead.
- Changes make the code work in 2023 HOT 2
- custom SSD300 model
- error while training with custom dataset in COCO format
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 ssd_keras.