def get_single_image_input(img_url, save_dir='/tmp'): img_name = img_url.split("/")[-1] img_path = os.path.join(save_dir, img_name) download(img_url, img_path) orig_img = Image.open(img_path) orig_img = orig_img.resize((img_width, img_height), Image.LANCZOS) img = np.array(orig_img)[:, :, (0, 1, 2)].astype('uint8') return img, orig_img, img_path
""" import numpy as np import decord import torch from gluoncv.torch.utils.model_utils import download from gluoncv.torch.data.transforms.videotransforms import video_transforms, volume_transforms from gluoncv.torch.engine.config import get_cfg_defaults from gluoncv.torch.model_zoo import get_model ################################################################ # Then, we download a video and extract a 32-frame clip from it. url = 'https://github.com/bryanyzhu/tiny-ucf101/raw/master/abseiling_k400.mp4' video_fname = download(url) vr = decord.VideoReader(video_fname) frame_id_list = range(0, 64, 2) video_data = vr.get_batch(frame_id_list).asnumpy() ################################################################ # Now we define transformations for the video clip. # This transformation function does four things: # (1) resize the shorter side of video clip to short_side_size, # (2) center crop the video clip to crop_size x crop_size, # (3) transpose the video clip to ``num_channels*num_frames*height*width``, # and (4) normalize it with mean and standard deviation calculated across all ImageNet images. crop_size = 224 short_side_size = 256 transform_fn = video_transforms.Compose([