Comments (7)
Not a demo.py like the one in py-faster-rcnn
, but you can look at this notebook for an example on how to visualize the results from Pascal VOC.
ps. if you want you can make a PR for one.
from keras-retinanet.
from keras-retinanet.
You need to let keras know where some of the custom objects are, by calling model = keras.models.load_model("model.h5", custom_objects=keras_retinanet.custom_objects)
.
However, as of writing this model loading is broken. The workaround is to create an identical model and call models.load_weights("model.h5", by_name=True)
. Or alternatively load the model definition first and then load weights. The rest can be seen in the notebook.
from keras-retinanet.
It works with models.load_weights("model.h5", by_name=True).
Now I am facing a different issue which use mode. predict with one input image. My code is below:
print('Creating model, this may take a second...')
model = create_model()
model.load_weights("snapshots/resnet50_voc_final.h5", by_name=True)
image = cv2.imread(sys.argv[1])
image -= min(image.flatten())
image /= max(image.flatten())
image *= 255
image = image.astype(np.uint8)
start = time.time()
predictions, detections = model.predict(image)
print("processing time: ", time.time() - start)
im = image.copy()
predicted_labels = np.argmax(detections[0, :, 4:], axis=1)
scores = np.max(detections[0, :, 4:], axis=1)
for idx, (label, score) in enumerate(zip(predicted_labels, scores)):
if label == 0:
continue
b = detections[0, idx, :4].astype(int)
cv2.rectangle(im, (b[0], b[1]), (b[2], b[3]), (0, 255, 0), 3)
caption = "{} {:.3f}".format(class_names[label], score)
cv2.putText(im, caption, (b[0], b[1] - 10), cv2.FONT_HERSHEY_PLAIN, 1.5, (0, 0, 0), 3)
cv2.putText(im, caption, (b[0], b[1] - 10), cv2.FONT_HERSHEY_PLAIN, 1.5, (255, 255, 255), 2)
plt.figure(figsize=(15, 15))
plt.axis('off')
plt.imshow(im)
plt.show()
But I got the following errors:
Traceback (most recent call last):
File "./examples/demo-pascal.py", line 65, in
predictions, detections = model.predict(image)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/training.py", line 1695, in predict
check_batch_axis=False)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/training.py", line 132, in _standardize_input_data
str(array.shape))
ValueError: Error when checking : expected input_1 to have 4 dimensions, but got array with shape (1288, 2048, 3)
from keras-retinanet.
You don't preprocess your image properly. It should firstly have 4 dimension ((batch, height, width, channels)
). In addition the imagenet mean should be subtracted and the image should be rescaled by 1/255. For an example on how to preprocess an image you can look here : https://github.com/delftrobotics/keras-retinanet/blob/master/keras_retinanet/preprocessing/coco.py#L107
Perhaps I'll add a demo.py which follows this use case, but for now you could try replicating the preprocessing steps from the data generator.
PS. It's not so much that preprocessing has to be done this way, but it does have to be consistent with what you used during training.
from keras-retinanet.
Do you still have a plan to add demo.py?
Thanks,
from keras-retinanet.
Not really no. If you make a nice one we can add it to the repository.
from keras-retinanet.
Related Issues (20)
- Training images dimesions and effect on output
- No bounding boxes when running evaluate.py HOT 2
- Training issue HOT 1
- TypeError: ('Keyword argument not understood:', 'freeze') HOT 1
- How to deal with images containing no labels HOT 1
- ERROR:gpu_init.cc(454)] Passthrough is not supported, GL is disabled, ANGLE is HOT 1
- Value Not Accepted: invalid literal HOT 1
- Extracting and saving mAP during training HOT 1
- Training Issue HOT 1
- when training yolov5 on custom dataset on spider show this error? how to resolve this error in pc? HOT 1
- COCO Large category and Anchor boxes generator HOT 1
- Error is displayed when running efficientnet: No module named 'efficientnet'
- Project dependencies may have API risk issues HOT 2
- InceptionV3 error HOT 1
- ModuleNotFoundError: No module named 'keras_retinanet.utils.compute_overlap' HOT 2
- 2023 Model
- Bad mAP results after long train HOT 1
- How to plot the metrics of my custom train
- Error occurred when finalizing GeneratorDataset iterator: FAILED_PRECONDITION: Python interpreter state is not initialized. The process may be terminated. HOT 3
- flag `--patience` (epochs to wait for no observable improvement for early stopping of training)
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 keras-retinanet.