How to select 1 sample but keep batch dimension in effiency way?

from import read_video, write_video
from import write_png
import os
v, a, info = read_video("/home/tt/Videos/VID_20201202_133703_090.mp4", pts_unit='sec')
print(v.shape)  # torch.Size([467, 1080, 1920, 3])
single_frame = v[100]
print(single_frame.shape)  # torch.Size([1080, 1920, 3])

batch_size_one = single_frame.unsqueeze(0)
print(batch_size_one.shape) # torch.Size([1, 1080, 1920, 3])

It required an unsqueeze.
It might not efficiency.

I would like to get the frame and predict (model that train on single image).

I am not sure if unsqueeze() has a computation overhead. Does it?

Alternatively, you can use single_frame = v[100:101] to select single frame that contains a 1 in batch dimension.