mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-05 23:38:42 +08:00
Create a base_encoder object, + refactor
This commit is contained in:
1 parent
a5c6139994
commit
18208f7aaa
6 files changed
+141
-40
No files matched your search
@@ -0,0 +1,35 @@
|
||||
from abc import abstractmethod, abstractproperty
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Type
|
||||
|
||||
import torch
|
||||
|
||||
from nerfstudio.configs import base_config as cfg
|
||||
|
||||
# TODO(cmk) want to rename ImageEncoder to be more generic
|
||||
@dataclass
|
||||
class BaseImageEncoderConfig(cfg.InstantiateConfig):
|
||||
_target: Type = field(default_factory=lambda: BaseImageEncoder)
|
||||
name: str = ""
|
||||
"""name of the encoder"""
|
||||
description: str = ""
|
||||
"""description of the encoder"""
|
||||
|
||||
class BaseImageEncoder:
|
||||
@abstractproperty
|
||||
def embedding_dim(self) -> int:
|
||||
"""
|
||||
returns the dimension of the embeddings
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def encode_image(self, input: torch.Tensor) -> torch.Tensor:
|
||||
"""
|
||||
Given a batch of input images, return their encodings
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def get_relevancy(self, embed: torch.Tensor, positive_id: int) -> torch.Tensor:
|
||||
"""
|
||||
Given a batch of embeddings, return the relevancy to the given positive id
|
||||
"""
|
||||
Reference in new issue
Block a user