Hi,
I’m doing some experiments with the Jetbot collision avoidance example and I wonder, how to display the framerate during the “live_demo” mode.
Is that possible?
Thanks,
Lars
Hi,
I’m doing some experiments with the Jetbot collision avoidance example and I wonder, how to display the framerate during the “live_demo” mode.
Is that possible?
Thanks,
Lars
Hi,
Yes. You can show the framerate with putText function:
cv2.putText(image, "xx fps",(x_pos,y_pos), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,255,255), 2, cv2.LINE_AA)
Thanks.
Hi AastaLLL,
thank you for your answer.
But where can I find the information “xx fps”. I couldn’t implement your code snippet in the live_demo.ipynb, because x_pos, y_pos is unknown (I did insert some Integer values in range of the image frame instead…) and image (img) is not a numpy array, neither a scalar (I have to find a working solution for that…), but I think, when I’m able to run that code, it will output “xx fps” and not the real fps value, right?
Best regards,
Lars
Hi Orandus,
You can accomplish this by modifying the execution cell as follows.
import torch.nn.functional as F
import time
t0 = time.time()
t1 = time.time()
fps_widget = widgets.FloatText(description='fps')
display(fps_widget)
def update(change):
global blocked_slider, robot, t0, t1
x = change['new']
x = preprocess(x)
y = model(x)
# we apply the `softmax` function to normalize the output vector so it sums to 1 (which makes it a probability distribution)
y = F.softmax(y, dim=1)
prob_blocked = float(y.flatten()[0])
blocked_slider.value = prob_blocked
if prob_blocked < 0.5:
robot.forward(0.4)
else:
robot.left(0.4)
# update FPS widget
t1 = time.time()
fps_widget.value = 1.0 / (t1 - t0)
t0 = t1
time.sleep(0.001)
update({'new': camera.value}) # we call the function once to intialize
Please note, this FPS will be reduced by the network latency, because updating the widgets requires synchronization with the browser.
If you want to test the achievable FPS (without browser visualization), you will need to remove calls to set browser side widget values from the control loop.
Please let me know if you have any questions.
Best,
John