text
stringlengths 0
828
|
|---|
image_path = database.original_file_name(f)
|
self.add_image(image_path, [annotation])"
|
776,"def save(self, list_file):
|
""""""Saves the current list of annotations to the given file.
|
**Parameters:**
|
``list_file`` : str
|
The name of a list file to write the currently stored list into
|
""""""
|
bob.io.base.create_directories_safe(os.path.dirname(list_file))
|
with open(list_file, 'w') as f:
|
for i in range(len(self.image_paths)):
|
f.write(self.image_paths[i])
|
for bbx in self.bounding_boxes[i]:
|
f.write(""\t[%f %f %f %f]"" % (bbx.top_f, bbx.left_f, bbx.size_f[0], bbx.size_f[1]))
|
f.write(""\n"")"
|
777,"def load(self, list_file):
|
""""""Loads the list of annotations from the given file and **appends** it to the current list.
|
``list_file`` : str
|
The name of a list file to load and append
|
""""""
|
with open(list_file) as f:
|
for line in f:
|
if line and line[0] != '#':
|
splits = line.split()
|
bounding_boxes = []
|
for i in range(1, len(splits), 4):
|
assert splits[i][0] == '[' and splits[i+3][-1] == ']'
|
bounding_boxes.append(BoundingBox(topleft=(float(splits[i][1:]), float(splits[i+1])), size=(float(splits[i+2]), float(splits[i+3][:-1]))))
|
self.image_paths.append(splits[0])
|
self.bounding_boxes.append(bounding_boxes)"
|
778,"def iterate(self, max_number_of_files=None):
|
""""""iterate([max_number_of_files]) -> image, bounding_boxes, image_file
|
Yields the image and the bounding boxes stored in the training set as an iterator.
|
This function loads the images and converts them to gray-scale.
|
It yields the image, the list of bounding boxes and the original image file name.
|
**Parameters:**
|
``max_number_of_files`` : int or ``None``
|
If specified, limit the number of returned data by sub-selection using :py:func:`quasi_random_indices`
|
**Yields:**
|
``image`` : array_like(2D)
|
The image loaded from file and converted to gray scale
|
``bounding_boxes`` : [:py:class:`BoundingBox`]
|
A list of bounding boxes, where faces are found in the image; might be empty (in case of pure background images)
|
`` image_file`` : str
|
The name of the original image that was read
|
""""""
|
indices = quasi_random_indices(len(self), max_number_of_files)
|
for index in indices:
|
image = bob.io.base.load(self.image_paths[index])
|
if len(image.shape) == 3:
|
image = bob.ip.color.rgb_to_gray(image)
|
# return image and bounding box as iterator
|
yield image, self.bounding_boxes[index], self.image_paths[index]"
|
779,"def _feature_file(self, parallel = None, index = None):
|
""""""Returns the name of an intermediate file for storing features.""""""
|
if index is None:
|
index = 0 if parallel is None or ""SGE_TASK_ID"" not in os.environ else int(os.environ[""SGE_TASK_ID""])
|
return os.path.join(self.feature_directory, ""Features_%02d.hdf5"" % index)"
|
780,"def extract(self, sampler, feature_extractor, number_of_examples_per_scale = (100, 100), similarity_thresholds = (0.5, 0.8), parallel = None, mirror = False, use_every_nth_negative_scale = 1):
|
""""""Extracts features from **all** images in **all** scales and writes them to file.
|
This function iterates over all images that are present in the internally stored list, and extracts features using the given ``feature_extractor`` for every image patch that the given ``sampler`` returns.
|
The final features will be stored in the ``feature_directory`` that is set in the constructor.
|
For each image, the ``sampler`` samples patch locations, which cover the whole image in different scales.
|
For each patch locations is tested, how similar they are to the face bounding boxes that belong to that image, using the Jaccard :py:meth:`BoundingBox.similarity`.
|
The similarity is compared to the ``similarity_thresholds``.
|
If it is smaller than the first threshold, the patch is considered as background, when it is greater the the second threshold, it is considered as a face, otherwise it is rejected.
|
Depending on the image resolution and the number of bounding boxes, this will usually result in some positive and thousands of negative patches per image.
|
To limit the total amount of training data, for all scales, only up to a given number of positive and negative patches are kept.
|
Also, to further limit the number of negative samples, only every ``use_every_nth_negative_scale`` scale is considered (for the positives, always all scales are processed).
|
To increase the number (especially of positive) examples, features can also be extracted for horizontally mirrored images.
|
Simply set the ``mirror`` parameter to ``True``.
|
Furthermore, this function is designed to be run using several parallel processes, e.g., using the `GridTK <https://pypi.python.org/pypi/gridtk>`_.
|
Each of the processes will run on a particular subset of the images, which is defined by the ``SGE_TASK_ID`` environment variable.
|
The ``parallel`` parameter defines the total number of parallel processes that are used.
|
**Parameters:**
|
``sampler`` : :py:class:`Sampler`
|
The sampler to use to sample patches of the images. Please assure that the sampler is set up such that it samples patch locations which can overlap with the face locations.
|
``feature_extractor`` : :py:class:`FeatureExtractor`
|
The feature extractor to be used to extract features from image patches
|
``number_of_examples_per_scale`` : (int, int)
|
The maximum number of positive and negative examples to extract for each scale of the image
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.