MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / _make_feed

Method _make_feed

imperative/python/megengine/jit/tracing.py:762–1043  ·  view source on GitHub ↗
(
        self,
        graph,
        outputs,
        input_data,
        repeat,
        silent,
        no_assert,
        maxerr,
        resize_input,
        input_transform,
    )

Source from the content-addressed store, hash-verified

760 self._trace.end_excluded_region()
761
762 def _make_feed(
763 self,
764 graph,
765 outputs,
766 input_data,
767 repeat,
768 silent,
769 no_assert,
770 maxerr,
771 resize_input,
772 input_transform,
773 ):
774 def auto_reformat_image(path, data, dst_shape):
775 """reformat image to target shape
776
777 :param data: image data as numpy array
778 :param dst_shape: target shape
779 """
780 dim3_format = False # required input format does not contain batch
781 hwc_format = False # required input format is NHWC
782
783 if not dst_shape: # input tensor shape is not predefined
784 if len(data.shape) == 2:
785 chl = 1
786 h = data.shape[0]
787 w = data.shape[1]
788 else:
789 assert (
790 len(data.shape) == 3
791 ), "Input image must be of dimension 2 or 3"
792 h, w, chl = data.shape
793 dst_shape = (1, chl, h, w)
794
795 if len(dst_shape) == 3:
796 dst_shape = (1,) + dst_shape
797 dim3_format = True
798
799 assert len(dst_shape) == 4, "bad dst_shape: {}".format(dst_shape)
800 chl = dst_shape[1]
801 if chl in [1, 3]:
802 n, c, h, w = dst_shape
803 dst_shape = (n, h, w, c)
804 else:
805 chl = dst_shape[3]
806 assert chl in [
807 1,
808 3,
809 ], "can not infer input format from shape: {}".format(dst_shape)
810 hwc_format = True
811
812 # dst_shape has now been normalized to NHWC format
813
814 if resize_input:
815 h, w = dst_shape[1:3]
816 data = cv2.resize(data, (w, h))
817 logger.info("input {} resized to {}".format(path, data.shape))
818
819 if chl == 1:

Callers 1

dumpMethod · 0.95

Calls 15

listFunction · 0.85
itemsMethod · 0.80
keysMethod · 0.80
joinMethod · 0.80
CompNodeMethod · 0.80
make_h2dMethod · 0.80
replace_varsMethod · 0.45
compileMethod · 0.45
appendMethod · 0.45
formatMethod · 0.45
infoMethod · 0.45
minMethod · 0.45

Tested by

no test coverage detected