Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
Create generators for training and validation.
Args
args: parseargs object containing configuration for generators.
preprocess_image: Function that preprocesses an image for the network.
"""
common_args = {
'batch_size': args.batch_size,
'input_size': args.input_size,
}
# create random transform generator for augmenting training data
if args.random_transform:
misc_effect = MiscEffect(border_value=0)
visual_effect = VisualEffect()
else:
misc_effect = None
visual_effect = None
if args.dataset_type == 'pascal':
from generators.pascal import PascalVocGenerator
train_generator = PascalVocGenerator(
args.pascal_path,
'trainval',
skip_difficult=True,
multi_scale=args.multi_scale,
misc_effect=misc_effect,
visual_effect=visual_effect,
**common_args
)
image = solarize(image, prob=self.solarize_prob, threshold=self.solarize_threshold)
return image
if __name__ == '__main__':
from generators.pascal import PascalVocGenerator
import cv2
train_generator = PascalVocGenerator(
'datasets/VOC0712',
'trainval',
skip_difficult=True,
anchors_path='voc_anchors_416.txt',
batch_size=1
)
visual_effect = VisualEffect()
for i in range(train_generator.size()):
image = train_generator.load_image(i)
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
annotations = train_generator.load_annotations(i)
boxes = annotations['bboxes']
for box in boxes.astype(np.int32):
cv2.rectangle(image, (box[0], box[1]), (box[2], box[3]), (0, 0, 255), 2)
src_image = image.copy()
image = visual_effect(image)
cv2.namedWindow('image', cv2.WINDOW_NORMAL)
cv2.imshow('image', np.concatenate([src_image, image], axis=1))
cv2.waitKey(0)
"""
Create generators for training and validation.
Args
args: parseargs object containing configuration for generators.
preprocess_image: Function that preprocesses an image for the network.
"""
common_args = {
'batch_size': args.batch_size,
'phi': args.phi,
}
# create random transform generator for augmenting training data
if args.random_transform:
misc_effect = MiscEffect()
visual_effect = VisualEffect()
else:
misc_effect = None
visual_effect = None
if args.dataset_type == 'pascal':
from generators.pascal import PascalVocGenerator
train_generator = PascalVocGenerator(
args.pascal_path,
'trainval',
skip_difficult=True,
misc_effect=misc_effect,
visual_effect=visual_effect,
**common_args
)
validation_generator = PascalVocGenerator(
filename = self.image_names[image_index] + '.xml'
try:
tree = ET.parse(os.path.join(self.data_dir, 'Annotations', filename))
return self.__parse_annotations(tree.getroot())
except ET.ParseError as e:
raise_from(ValueError('invalid annotations file: {}: {}'.format(filename, e)), None)
except ValueError as e:
raise_from(ValueError('invalid annotations file: {}: {}'.format(filename, e)), None)
if __name__ == '__main__':
from augmentor.misc import MiscEffect
from augmentor.color import VisualEffect
misc_effect = MiscEffect(border_value=0)
visual_effect = VisualEffect()
generator = PascalVocGenerator(
'datasets/VOC0712',
'trainval',
skip_difficult=True,
misc_effect=misc_effect,
visual_effect=visual_effect,
batch_size=1
)
for inputs, targets in generator:
print('hi')