MCPcopy
hub / github.com/facebookresearch/mmf / Sample

Class Sample

pythia/common/sample.py:21–55  ·  view source on GitHub ↗

Sample represent some arbitary data. All datasets in Pythia must return an object of type ``Sample``. Args: init_dict (Dict): Dictionary to init ``Sample`` class with. Usage:: >>> sample = Sample({"text": torch.tensor(2)}) >>> sample.text.zero_() # Cust

Source from the content-addressed store, hash-verified

19
20
21class Sample(OrderedDict):
22 """Sample represent some arbitary data. All datasets in Pythia must
23 return an object of type ``Sample``.
24
25 Args:
26 init_dict (Dict): Dictionary to init ``Sample`` class with.
27
28 Usage::
29
30 >>> sample = Sample({"text": torch.tensor(2)})
31 >>> sample.text.zero_()
32 # Custom attributes can be added to ``Sample`` after initialization
33 >>> sample.context = torch.tensor(4)
34 """
35
36 def __init__(self, init_dict={}):
37 super().__init__(init_dict)
38
39 def __setattr__(self, key, value):
40 self[key] = value
41
42 def __getattr__(self, key):
43 try:
44 return self[key]
45 except KeyError:
46 raise AttributeError(key)
47
48 def fields(self):
49 """Get current attributes/fields registered under the sample.
50
51 Returns:
52 List[str]: Attributes registered under the Sample.
53
54 """
55 return list(self.keys())
56
57
58class SampleList(OrderedDict):

Callers 13

test_caption_bleu4Method · 0.90
test_forwardMethod · 0.90
build_bbox_tensorsFunction · 0.90
load_itemMethod · 0.90
get_itemMethod · 0.90
load_itemMethod · 0.90
add_ocr_detailsMethod · 0.90
load_itemMethod · 0.90
_load_objectsMethod · 0.90
_load_relationshipsMethod · 0.90
_load_regionsMethod · 0.90
_fix_sample_typeMethod · 0.85

Calls

no outgoing calls

Tested by 2

test_caption_bleu4Method · 0.72
test_forwardMethod · 0.72