How to use _set_ids method in autotest

Best Python code snippet using autotest_python

dataset.py

Source:dataset.py Github

copy

Full Screen

1'''2Script containing functions related to dataset preparation3Author Courtesy: @ysbecca4Ref : https://github.com/ysbecca/Domain-Adaptation/blob/master/MNIST_USPS_Dataset/dataset.py5'''6import time7import mnist_usps_script as mnus8from datetime import timedelta9import numpy as np10class DataSet(object):11 def __init__(self, images, cls, set_ids):12 """ set_id = the dataset which the images belong to. 0 = MNIST; 1 = USPS """13 self._num_images = images.shape[0]14 # Convert shape from [num examples, rows, columns, depth]15 # to [num examples, rows*columns] (assuming depth == 1)16 # Convert from [0, 255] -> [0.0, 1.0].17 # images = images.astype(np.uint8)18 # images = np.multiply(images, 1.0 / 255.0)19 self._images = images20 self._cls = cls21 self._set_ids = set_ids22 # Set the labels based on cls. 23 labels = np.zeros((self._num_images, 10))24 for i, cls_ in enumerate(cls):25 labels[i][cls_] = 126 self._labels = labels27 self._epochs_completed = 028 self._index_in_epoch = 029 @property30 def images(self):31 return self._images32 @property33 def cls(self):34 return self._cls35 @property36 def labels(self):37 return self._labels38 @property39 def set_ids(self):40 return self._set_ids41 @property42 def num_images(self):43 return self._num_images44 @property45 def epochs_completed(self):46 return self._epochs_completed47 def set_images(self, images):48 self._images = images49 50 def remove_from_set(self, selected):51 ''' Removes the images at selected indices from the dataset. '''52 if(len(selected) != self._num_images):53 print("ERROR: number of selected indices does not match dataset size.")54 return55 num_removed = np.count_nonzero(selected)56 # Building new arrays instead of altering old ones for efficiency.57 new_images, new_cls, new_set_ids, new_labels = [], [], [], []58 for i, s in enumerate(selected):59 if s == 0:60 new_images.append(self._images[i])61 new_cls.append(self._cls[i])62 new_set_ids.append(self._set_ids[i])63 new_labels.append(self._labels[i])64 self._images = np.array(new_images)65 self._cls = np.array(new_cls)66 self._set_ids = np.array(new_set_ids)67 self._labels = np.array(new_labels)68 self._num_images -= num_removed69 def add_to_set(self, selected, dataset, preds):70 ''' Adds the images at the selected indices to the dataset and updates the params.'''71 num_added = np.count_nonzero(selected)72 max_preds = np.argmax(preds, axis=1) # Indices of the winning prediction (preds[max_preds[i]])73 images_, cls_, set_ids_, labels_ = [], [], [], []74 for i, s in enumerate(selected):75 if s > 0:76 images_.append(dataset.images[i])77 cls_.append(max_preds[i]) # Add class as PREDICTED by the CNN78 set_ids_.append(dataset.set_ids[i])79 new_label = np.zeros(10)80 new_label[max_preds[i]] = 181 labels_.append(new_label)82 # Add all the data.83 self._images = np.concatenate((self._images, images_))84 self._cls = np.concatenate((self._cls, cls_))85 self._set_ids = np.concatenate((self._set_ids, set_ids_))86 self._labels = np.concatenate((self._labels, labels_))87 self._num_images += num_added88 89 # Reshuffle everything the same way.90 perm = np.arange(self._num_images)91 np.random.shuffle(perm)92 self._images = self._images[perm]93 self._cls = self._cls[perm]94 self._set_ids = self._set_ids[perm]95 self._labels = self._labels[perm]96 def next_batch(self, batch_size):97 """Return the next `batch_size` examples from this data set."""98 start = self._index_in_epoch99 self._index_in_epoch += batch_size100 if self._index_in_epoch > self._num_images:101 # Finished epoch102 self._epochs_completed += 1103 # # Shuffle the data (maybe)104 # perm = np.arange(self._num_images)105 # np.random.shuffle(perm)106 # self._images = self._images[perm]107 # self._labels = self._labels[perm]108 # Start next epoch109 start = 0110 self._index_in_epoch = batch_size111 assert batch_size <= self._num_images112 end = self._index_in_epoch113 return self._images[start:end], self._labels[start:end] # self._cls[start:end], self._set_ids[start:end]114def generate_combined_dataset(mnist_dataset, usps_dataset):115 class DataSets(object):116 pass117 dataset = DataSets()118 # Complete MNIST119 dataset.train = DataSet(np.concatenate( \120 (mnist_dataset.train.images, mnist_dataset.valid.images, mnist_dataset.test.images)), \121 np.concatenate((mnist_dataset.train.cls, mnist_dataset.valid.cls, mnist_dataset.test.cls)), \122 np.concatenate((mnist_dataset.train.set_ids, mnist_dataset.valid.set_ids, mnist_dataset.test.set_ids)), \123 )124 dataset.test = DataSet(usps_dataset.test.images, usps_dataset.test.cls, usps_dataset.test.set_ids)125 # Only used to keep track of remaining USPS images not yet added in bootstrap iterations.126 dataset.usps_train = DataSet(usps_dataset.train.images, usps_dataset.train.cls, usps_dataset.train.set_ids)127 return dataset128def read_datasets():129 class DataSets(object):130 pass131 mnist_datasets = DataSets()132 usps_datasets = DataSets()133 start_time = time.time()134 # mnist_x[i]; 0 = train, 1 = valid, 2 = test135 mnist_x, usps_x, mnist_y, usps_y = mnus.dataset(normalisation=True, store=False)136 mnist_datasets.train = DataSet(mnist_x[0], mnist_y[0], np.zeros((len(mnist_y[0]))))137 mnist_datasets.valid = DataSet(mnist_x[1], mnist_y[1], np.zeros((len(mnist_y[1]))))138 mnist_datasets.test = DataSet(mnist_x[2], mnist_y[2], np.zeros((len(mnist_y[2]))))139 # For now, the USPS train includes the validation set, so:140 # usps_x[i]; 0 = train, 1 = test141 usps_datasets.train = DataSet(usps_x[0], usps_y[0], np.ones((len(usps_y[0]))))142 usps_datasets.test = DataSet(usps_x[1], usps_y[1], np.ones((len(usps_y[1]))))143 end_time = time.time()144 time_dif = end_time - start_time145 # print("Time elapsed: " + str(timedelta(seconds=int(round(time_dif)))))...

Full Screen

Full Screen

identity_list.py

Source:identity_list.py Github

copy

Full Screen

...34 def ids(self, ids: Union[List[str], bytes], sep: str = "\n"):35 if isinstance(ids, bytes):36 self._set_ids_from_bytes(ids, sep=sep)37 else:38 self._set_ids(ids)39 def _set_ids(self, ids: list):40 if ids:41 ids = [x for x in ids if x != ""] # drop trailing empties42 self.collector.save({"name": self.key, "count": len(ids), "ids": ids})43 logger.info(44 "Saved %s ids to %s/%s", len(ids), self.model.__name__, self.key45 )46 def _set_ids_from_bytes(self, ids: bytes, sep: str = "\n"):47 self._set_ids(ids=ids.decode().split(sep))48 def delete(self):49 self.model.objects(name=self.key).delete()50 self.ids = []51class WellList(IdentityList):52 def __init__(self, key: str, hole_direction: str):53 if hole_direction == HoleDirection.H.name:54 self.model = WellMasterHorizontal55 elif hole_direction == HoleDirection.V.name:56 self.model = WellMasterVertical57 else:58 raise ValueError(59 f"Invalid value for hole_direction ({hole_direction}) -- Valid options are {HoleDirection.member_names()}" # noqa60 )61 super().__init__(self.model, key)...

Full Screen

Full Screen

sets.py

Source:sets.py Github

copy

Full Screen

1from abc import ABC, abstractmethod2import numpy as np3class SetGenerator(ABC):4 def __init__(self, n_instances):5 """6 Generates a training set for the classifiers.7 :param n_instances: <int> Amount of instances to consider.8 """9 self._n_instances = n_instances10 self._set_ids = None11 @abstractmethod12 def training_ids(self):13 pass14 @abstractmethod15 def oob_ids(self):16 pass17 def clear(self):18 """19 Clears the set ids.20 """21 self._set_ids = None22class SimpleSet(SetGenerator):23 def training_ids(self):24 """25 Generates the ids of the training instances.26 :return: <numpy array>27 """28 if self._set_ids is None:29 self._set_ids = np.array(range(self._n_instances))30 return self._set_ids31 def oob_ids(self):32 """33 Returns an empty array. No out-of-bag instances for SimpleSet.34 :return: <numpy array>35 """36 return np.array([])37class BaggingSet(SetGenerator):38 def training_ids(self):39 """40 Generates the ids of the training instances.41 :return: <numpy array>42 """43 if self._set_ids is None:44 self._set_ids = np.random.choice(self._n_instances, replace=True, size=self._n_instances)45 return self._set_ids46 def oob_ids(self):47 """48 Returns the ids for the out-of-bag set.49 :return: <numpy array>50 """...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful