Open PranavMaddula opened 4 years ago
Hi, currently the API only supports predicting on images that are the same size as the training images, but this will be changed in a coming update. However, this is not hard to do using the Keras API. Here is some code that should accomplish what you want:
from deepposekit.models import load_model
import tensorflow as tf
model = load_model("/path/to/saved/model.h5")
predict_model = model.predict_model
predict_model.layers.pop(0) # remove current input layer
inputs = tf.keras.layers.Input((512, 512, 1))
outputs = predict_model(inputs)
predict_model = tf.keras.Model(inputs, outputs)
x = np.random.randint(0, 255, (16, 512, 512, 1), dtype=np.uint8)
prediction = predict_model.predict(x, verbose=True)
Thanks!
Setting predict_model = model.predict_model
worked perfectly!
Another question, however, Is there an easy way to change the dimensions of the poster overlay video generation function? Right now it only appears to work with frames that are of the same size as the training set (frame size of DataGenerator)
I have tried writer = VideoWriter(HOME + '/Data/posture.mp4', (512*2,512*2), 'MP4V', 30.0)
to have the correct dimensions for the video I am aiming to process (in my case 512x512)
Doing this allows me to successfully write a viewable video, however, the posture overlay does not appear.
I have also tried to scale the predictions predictions *= 4.2*2
, as my training data is 160x160 and my video is 512x512. I also changed the resized_shape to resized_shape = (int(data_generator.image_shape[0]*3.2*2), int(data_generator.image_shape[1]*3.2*2))
, however, this also does not generate the posture overlay on the video.
Any ideas or advice would be much appreciated! Thanks!
Update: I got it working now.
scaling resized_shape
and updating the writer parameters to the video size appears to have done it. Not sure why It did not work the first time I ran it, but it works now.
This brings me a new question: Is it possible to scale already annotated images so that the images that are categorized as outliers can be added to the initial annotation set so that the model can be easily retrained?
Thanks again!
Hi, I'm not sure exactly what you mean, but currently all of the images in the training set must be the same size.
From the steps in the 'DeepPoseKit Step 3 - Train a model' I have trained a model for locust pose mapping. However, the data used in the annotation set is 160x160. When following the steps in the 'DeepPoseKit Step 4b - Predict on new data' notebook, I get the following issue:
reader = VideoReader(HOME + '/Data/crop.mp4', batch_size=50, gray=True) predictions = model.predict(reader, verbose=1) reader.close()
`--------------------------------------------------------------------------- ValueError Traceback (most recent call last)