generate input for different model type Args: imgs (list(numpy)): list of images (np.ndarray) im_info (list(dict)): list of image info Returns: inputs (dict): input of model
(imgs, im_info)
| 848 | |
| 849 | |
| 850 | def create_inputs(imgs, im_info): |
| 851 | """generate input for different model type |
| 852 | Args: |
| 853 | imgs (list(numpy)): list of images (np.ndarray) |
| 854 | im_info (list(dict)): list of image info |
| 855 | Returns: |
| 856 | inputs (dict): input of model |
| 857 | """ |
| 858 | inputs = {} |
| 859 | |
| 860 | im_shape = [] |
| 861 | scale_factor = [] |
| 862 | if len(imgs) == 1: |
| 863 | inputs['image'] = np.array((imgs[0], )).astype('float32') |
| 864 | inputs['im_shape'] = np.array( |
| 865 | (im_info[0]['im_shape'], )).astype('float32') |
| 866 | inputs['scale_factor'] = np.array( |
| 867 | (im_info[0]['scale_factor'], )).astype('float32') |
| 868 | return inputs |
| 869 | |
| 870 | for e in im_info: |
| 871 | im_shape.append(np.array((e['im_shape'], )).astype('float32')) |
| 872 | scale_factor.append(np.array((e['scale_factor'], )).astype('float32')) |
| 873 | |
| 874 | inputs['im_shape'] = np.concatenate(im_shape, axis=0) |
| 875 | inputs['scale_factor'] = np.concatenate(scale_factor, axis=0) |
| 876 | |
| 877 | imgs_shape = [[e.shape[1], e.shape[2]] for e in imgs] |
| 878 | max_shape_h = max([e[0] for e in imgs_shape]) |
| 879 | max_shape_w = max([e[1] for e in imgs_shape]) |
| 880 | padding_imgs = [] |
| 881 | for img in imgs: |
| 882 | im_c, im_h, im_w = img.shape[:] |
| 883 | padding_im = np.zeros( |
| 884 | (im_c, max_shape_h, max_shape_w), dtype=np.float32) |
| 885 | padding_im[:, :im_h, :im_w] = img |
| 886 | padding_imgs.append(padding_im) |
| 887 | inputs['image'] = np.stack(padding_imgs, axis=0) |
| 888 | return inputs |
| 889 | |
| 890 | |
| 891 | class PredictConfig(): |