INNER CODE UNIT · Python
estimate
BrokenSource/DepthFlow · depthflow/estimators/__init__.py:24
def estimate(self, image: np.ndarray) -> np.ndarray:
hasher = xxhash.xxh3_64()
hasher.update(self.__hash__().to_bytes(8))
hasher.update(image.tobytes())
key: int = hasher.intdigest()
# Grab only rgb channels
if (image.shape[-1] == 4):
image = image[..., :3]
# Avoid expensive methods when cached
if (depth := DEPTHMAPS.get(key)) is None:
self.load_model()
depth = self._estimate(image)
depth = self.normalize(depth)
DEPTHMAPS.set(key, depth)
# Normalized f32 for GPU