braincog.datasets.NOmniglot package
Submodules
braincog.datasets.NOmniglot.NOmniglot module
braincog.datasets.NOmniglot.nomniglot_full module
- class braincog.datasets.NOmniglot.nomniglot_full.NOmniglotfull(root='data/', train=True, frames_num=4, data_type='event', transform=None, target_transform=None, use_npz=False, crop=True, create=True)
基类:
Dataset
solve few-shot learning as general classification problem, We combine the original training set with the test set and take 3/4 as the training set
braincog.datasets.NOmniglot.nomniglot_nw_ks module
- class braincog.datasets.NOmniglot.nomniglot_nw_ks.NOmniglotNWayKShot(root, n_way, k_shot, k_query, train=True, frames_num=12, data_type='event', transform=Resize(size=(28, 28), interpolation=bilinear, max_size=None, antialias=None))
基类:
Dataset
get n-wway k-shot data as meta learning We set the sampling times of each epoch as “len(self.dataSet) // (self.n_way * (self.k_shot + self.k_query))” you can increase or decrease the number of epochs to determine the total training times
- load_data_cache(data_dict, length)
The dataset is sampled randomly length times, and the address is saved to obtain
- reset()
braincog.datasets.NOmniglot.nomniglot_pair module
- class braincog.datasets.NOmniglot.nomniglot_pair.NOmniglotTestSet(root='data/', time=1000, way=20, shot=1, query=1, use_frame=True, frames_num=10, data_type='event', use_npz=True, resize=None)
基类:
Dataset
Dataloader for Siamese Net
- class braincog.datasets.NOmniglot.nomniglot_pair.NOmniglotTrainSet(root='data/', use_frame=True, frames_num=10, data_type='event', use_npz=False, resize=None)
基类:
Dataset
Dataloader for Siamese Net The pairs of similar samples are labeled as 1, and those of different samples are labeled as 0
- braincog.datasets.NOmniglot.nomniglot_pair.npc()
choice(a, size=None, replace=True, p=None)
Generates a random sample from a given 1-D array
在 1.7.0 版本加入.
备注
New code should use the
choice
method of adefault_rng()
instance instead; please see the random-quick-start.- 参数
a (1-D array-like or int) – If an ndarray, a random sample is generated from its elements. If an int, the random sample is generated as if it were
np.arange(a)
size (int or tuple of ints, optional) – Output shape. If the given shape is, e.g.,
(m, n, k)
, thenm * n * k
samples are drawn. Default is None, in which case a single value is returned.replace (boolean, optional) – Whether the sample is with or without replacement. Default is True, meaning that a value of
a
can be selected multiple times.p (1-D array-like, optional) – The probabilities associated with each entry in a. If not given, the sample assumes a uniform distribution over all entries in
a
.
- 返回
samples – The generated random samples
- 返回类型
single item or ndarray
- 抛出
ValueError – If a is an int and less than zero, if a or p are not 1-dimensional, if a is an array-like of size 0, if p is not a vector of probabilities, if a and p have different lengths, or if replace=False and the sample size is greater than the population size
参见
randint
,shuffle
,permutation
Generator.choice
which should be used in new code
备注
Setting user-specified probabilities through
p
uses a more general but less efficient sampler than the default. The general sampler produces a different sample than the optimized sampler even if each element ofp
is 1 / len(a).Sampling random rows from a 2-D array is not possible with this function, but is possible with Generator.choice through its
axis
keyword.示例
Generate a uniform random sample from np.arange(5) of size 3:
>>> np.random.choice(5, 3) array([0, 3, 4]) # random >>> #This is equivalent to np.random.randint(0,5,3)
Generate a non-uniform random sample from np.arange(5) of size 3:
>>> np.random.choice(5, 3, p=[0.1, 0, 0.3, 0.6, 0]) array([3, 3, 0]) # random
Generate a uniform random sample from np.arange(5) of size 3 without replacement:
>>> np.random.choice(5, 3, replace=False) array([3,1,0]) # random >>> #This is equivalent to np.random.permutation(np.arange(5))[:3]
Generate a non-uniform random sample from np.arange(5) of size 3 without replacement:
>>> np.random.choice(5, 3, replace=False, p=[0.1, 0, 0.3, 0.6, 0]) array([2, 3, 0]) # random
Any of the above can be repeated with an arbitrary array-like instead of just integers. For instance:
>>> aa_milne_arr = ['pooh', 'rabbit', 'piglet', 'Christopher'] >>> np.random.choice(aa_milne_arr, 5, p=[0.5, 0.1, 0.1, 0.3]) array(['pooh', 'pooh', 'pooh', 'Christopher', 'piglet'], # random dtype='<U11')
braincog.datasets.NOmniglot.utils module
- class braincog.datasets.NOmniglot.utils.FunctionThread(f, *args, **kwargs)
基类:
Thread
- run()
Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
- braincog.datasets.NOmniglot.utils.convert_aedat4_dir_to_events_dir(root, train)
- braincog.datasets.NOmniglot.utils.convert_events_dir_to_frames_dir(events_data_dir, frames_data_dir, suffix, frames_num=12, result_type='event', thread_num=1, compress=True)
Iterate through all event data in eventS_date_DIR and generate frame data files in frames_data_DIR
- braincog.datasets.NOmniglot.utils.integrate_events_to_frames(events, height, width, frames_num=10, data_type='event')
- braincog.datasets.NOmniglot.utils.list_all_files(root, suffix, getlen=False)
List the path of all files under root, output a list
- braincog.datasets.NOmniglot.utils.list_class_files(root, frames_kind_root, getlen=False, use_npz=False)
index the generated samples, get dictionaries according to categories, each corresponding to a list, the list contain the address of the new file in fnum_x_dtype_x_npz_True
- braincog.datasets.NOmniglot.utils.normalize_frame(frames: ndarray, normalization: str)
- braincog.datasets.NOmniglot.utils.num2str(idx)