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

Function get_dsize

imperative/python/megengine/functional/vision.py:531–568  ·  view source on GitHub ↗
(scale_factor)

Source from the content-addressed store, hash-verified

529 ), "shape of input tensor must correspond to the operartion mode"
530
531 def get_dsize(scale_factor):
532 if isinstance(scale_factor, (float, int)):
533 scale_factor = float(scale_factor)
534 if mode == "linear":
535 scale_factor = (scale_factor, float(1))
536 elif mode == "trilinear":
537 scale_factor = (scale_factor, scale_factor, scale_factor)
538 else:
539 scale_factor = (scale_factor, scale_factor)
540 else:
541 if mode == "linear":
542 raise ValueError(
543 "under linear mode, scale_factor can only be single value"
544 )
545
546 if mode == "trilinear":
547 assert (
548 len(scale_factor) == 3
549 ), f"shape of scale_factor of interpolate-{mode} must be equal to (3, )"
550 else:
551 assert (
552 len(scale_factor) == 2
553 ), f"shape of scale_factor of interpolate-{mode} must be equal to (2, )"
554 assert all(
555 isinstance(x, (float, int)) for x in scale_factor
556 ), f"scale_factor of interpolate must be float/int type"
557 dsize = [
558 floor(
559 Tensor(
560 inp.shape[i + 2] * float(scale_factor[i]),
561 dtype="float32",
562 device=inp.device,
563 )
564 )
565 for i in range(len(scale_factor))
566 ]
567 dsize = concat(dsize, axis=0)
568 return dsize
569
570 if size is None:
571 if scale_factor is None:

Callers 1

interpolateFunction · 0.85

Calls 3

floorFunction · 0.70
concatFunction · 0.70
TensorClass · 0.50

Tested by

no test coverage detected