I have tested P3D-Pytorch. it’s pretty simple and should share similar process with I3D.

Pre-process:  For each frame in a clip, there is pre-process like subtracting means, divide std.
An example:


import cv2
mean = (104 / 255.0, 117 / 255.0 ,123 / 255.0)
std     = (0.225, 0.224, 0.229)
frame = cv2.imread(“a string to image path”)
frame /= 255.0 # [0, 255] -> [0, 1]
frame -= mean # subtract means
frame /= std      # div std
frame = frame[:, : , (2, 1, 0)] # covert BGR image to RGB image


A clip is a stack of frames with frame size H x W x 3 and clip size T x H x W x 3
since P3D requires input in form of 3 x T x H x W, perform:


clip = clip.permte(3, 0, 1, 2).contiguous()


Load P3D model
(P3D, Bottleneck, p3d_model_path can be found in the mentioned github.)


model =  P3D(Bottleneck, [3, 8, 36, 3], modality = ‘RGB’)
p3d_weights = torch.load(“a string to p3d model path”)[‘state_dict’]
model.load_state_dict(p3d_weights)
out=model(data)
print(out.size(),out)