wbia_cnn package¶
Subpackages¶
- wbia_cnn.models package
- Submodules
- wbia_cnn.models._model_legacy module
- wbia_cnn.models.abstract_models module
- wbia_cnn.models.aoi module
- wbia_cnn.models.aoi2 module
- wbia_cnn.models.background module
- wbia_cnn.models.classifier module
- wbia_cnn.models.classifier2 module
- wbia_cnn.models.dummy module
- wbia_cnn.models.labeler module
- wbia_cnn.models.mnist module
- wbia_cnn.models.pretrained module
- wbia_cnn.models.quality module
- wbia_cnn.models.siam module
- wbia_cnn.models.viewpoint module
- Module contents
Submodules¶
wbia_cnn._plugin module¶
tests a test set of data using a specified, pre-trained model and weights
python -c “import wbia_cnn”
-
wbia_cnn._plugin.
_suggest_random_candidate_regions
(ibs, image, min_size, num_candidates=2000)[source]¶
-
wbia_cnn._plugin.
detect_annot_species_viewpoint_cnn
(ibs, aid_list)[source]¶ - Parameters
ibs (IBEISController) – ibeis controller object
aid_list (int) – list of annotation ids
- Returns
species_viewpoint_list
- Return type
list
- CommandLine:
python -m wbia_cnn._plugin –exec-detect_annot_species_viewpoint_cnn
Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn._plugin import * # NOQA >>> import wbia >>> ibs = wbia.opendb(defaultdb='testdb1') >>> aid_list = ibs.get_valid_aids() >>> species_viewpoint_list = detect_annot_species_viewpoint_cnn(ibs, aid_list) >>> result = ('species_viewpoint_list = %s' % (str(species_viewpoint_list),)) >>> print(result)
-
wbia_cnn._plugin.
detect_annot_whale_fluke_background_mask
(ibs, aid_list, species='whale_fluke', config2_=None)[source]¶ - Parameters
ibs (IBEISController) – ibeis controller object
aid_list (int) – list of annotation ids
- Returns
mask_list
- Return type
list
-
wbia_cnn._plugin.
detect_annot_zebra_background_mask
(ibs, aid_list, species=None, config2_=None)[source]¶ - Parameters
ibs (IBEISController) – ibeis controller object
aid_list (int) – list of annotation ids
- Returns
mask_list
- Return type
list
-
wbia_cnn._plugin.
detect_image_cnn
(ibs, gid, confidence=0.9, extraction='bing')[source]¶ - Parameters
ibs (IBEISController) – ibeis controller object
gid –
confidence (float) – (default = 0.9)
extraction (str) – (default = ‘bing’)
- CommandLine:
python -m wbia_cnn._plugin –exec-detect_image_cnn
Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn._plugin import * # NOQA >>> from wbia_cnn._plugin import _suggest_random_candidate_regions, _suggest_bing_candidate_regions # NOQA >>> import wbia >>> ibs = wbia.opendb(defaultdb='testdb1') >>> gid = 1 >>> confidence = 0.9 >>> extraction = 'bing' >>> result = detect_image_cnn(ibs, gid, confidence, extraction) >>> print(result)
-
wbia_cnn._plugin.
extract_siam128_vecs
(chip_list, kpts_list)[source]¶ Duplicate testing func for vtool
-
wbia_cnn._plugin.
fix_annot_species_viewpoint_quality_cnn
(ibs, aid_list, min_conf=0.8)[source]¶ - Parameters
ibs (IBEISController) – ibeis controller object
aid_list (int) – list of annotation ids
-
wbia_cnn._plugin.
generate_chip_label_list
(ibs, chip_list, nInput=None, labeler_weight_filepath=None, **kwargs)[source]¶
-
wbia_cnn._plugin.
generate_siam_l2_128_feats
(ibs, cid_list, config2_=None)[source]¶ - Parameters
ibs (IBEISController) – ibeis controller object
cid_list (list) –
config2 (dict) – (default = None)
- CommandLine:
python -m wbia_cnn._plugin –test-generate_siam_l2_128_feats python -m wbia_cnn._plugin –test-generate_siam_l2_128_feats –db PZ_Master0
- SeeAlso:
~/code/ibeis/ibeis/algo/preproc/preproc_feat.py
Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn._plugin import * # NOQA >>> import wbia >>> ibs = wbia.opendb(defaultdb='testdb1') >>> cid_list = ibs.depc_annot.get_rowids('chips', ibs.get_valid_aids()) >>> config2_ = None >>> # megahack >>> cfg = Config.FeatureConfig() # fixme >>> config2_ = dict(feat_type='hesaff+siam128', >>> feat_cfgstr=cfg.feat_cfg.get_cfgstr().replace('sift', 'siam128'), >>> hesaff_params=cfg.feat_cfg.get_hesaff_params()) >>> featgen = generate_siam_l2_128_feats(ibs, cid_list, config2_) >>> result = ut.depth_profile(list(featgen)) >>> print(result)
-
wbia_cnn._plugin.
generate_species_background
(ibs, chip_list, species=None, nInput=None)[source]¶ TODO: Use this as the primary function
- CommandLine:
python -m wbia_cnn._plugin –exec-generate_species_background –db PZ_MTEST –species=zebra_plains –show python -m wbia_cnn._plugin –exec-generate_species_background –db GZ_Master1 –species=zebra_grevys –save cnn_detect_results_gz.png –diskshow –clipwhite python -m wbia_cnn._plugin –exec-generate_species_background –db PZ_Master1 –species=zebra_plains –save cnn_detect_results_pz.png –diskshow –clipwhite python -m wbia_cnn._plugin –exec-generate_species_background –db PZ_Master1 –show python -m wbia_cnn._plugin –exec-generate_species_background –db GZ_Master1 –show python -m wbia_cnn._plugin –exec-generate_species_background –db GIRM_Master1 –show –species=giraffe_masai
Example
>>> # ENABLE_DOCTEST >>> import wbia_cnn >>> import wbia >>> from wbia_cnn._plugin import * # NOQA >>> ibs = wbia.opendb(defaultdb='testdb1') >>> aid_list = ibs.get_valid_aids()[0:8] >>> species = ut.get_argval('--species', type_=str, default='zebra_plains') >>> config2_ = None >>> nInput = len(aid_list) >>> chip_iter = ibs.get_annot_chips(aid_list, verbose=True, config2_=config2_, eager=False) >>> mask_iter = generate_species_background(ibs, chip_iter, species=species, nInput=nInput) >>> mask_list = list(mask_iter) >>> ut.quit_if_noshow() >>> import plottool as pt >>> import vtool as vt >>> chip_list = ibs.get_annot_chips(aid_list, verbose=True, config2_=config2_, eager=True) >>> stacked_list = [vt.stack_images(chip, mask)[0] for chip, mask in zip(chip_list, mask_list)] >>> iteract_obj = pt.interact_multi_image.MultiImageInteraction(stacked_list, nPerPage=4) >>> iteract_obj.start() >>> #hough_cpath = ibs.get_annot_probchip_fpath(aid_list, config2_=config2_) >>> #iteract_obj2 = pt.interact_multi_image.MultiImageInteraction(hough_cpath, nPerPage=4) >>> #pt.imshow(mask_list[0]) >>> ut.show_if_requested()
- Ignore:
#>>> from wbia_cnn.draw_results import * # NOQA #>>> from wbia_cnn import ingest_data #>>> data, labels = ingest_data.testdata_patchmatch2() #>>> flat_metadata = {‘fs’: np.arange(len(labels))} #>>> result = interact_siamsese_data_patches(labels, data, flat_metadata) #>>> ut.show_if_requested()
-
wbia_cnn._plugin.
generate_species_background_mask
(ibs, chip_fpath_list, species=None)[source]¶ - Parameters
ibs (IBEISController) – ibeis controller object
aid_list (int) – list of annotation ids
- Returns
species_viewpoint_list
- Return type
list
- CommandLine:
python -m wbia_cnn._plugin –exec-generate_species_background_mask –show –db PZ_Master1 python -m wbia_cnn –tf generate_species_background_mask –show –db PZ_Master1 –aid 9970
Example
>>> # DISABLE_DOCTEST >>> import wbia_cnn >>> import wbia >>> from wbia_cnn._plugin import * # NOQA >>> ibs = wbia.opendb(defaultdb='testdb1') >>> aid_list = ut.get_argval(('--aids', '--aid'), type_=list, default=ibs.get_valid_aids()[0:2]) >>> chip_fpath_list = ibs.get_annot_chip_fpath(aid_list) >>> species = ibs.const.TEST_SPECIES.ZEB_PLAIN >>> mask_list = generate_species_background_mask(ibs, chip_fpath_list, species) >>> mask_list = list(mask_list) >>> ut.quit_if_noshow() >>> import plottool as pt >>> iteract_obj = pt.interact_multi_image.MultiImageInteraction(mask_list, nPerPage=4) >>> #pt.imshow(mask_list[0]) >>> ut.show_if_requested()
#>>> from wbia_cnn.draw_results import * # NOQA #>>> from wbia_cnn import ingest_data #>>> data, labels = ingest_data.testdata_patchmatch2() #>>> flat_metadata = {‘fs’: np.arange(len(labels))} #>>> result = interact_siamsese_data_patches(labels, data, flat_metadata) #>>> ut.show_if_requested()
-
wbia_cnn._plugin.
generate_thumbnail_aoi2_list
(ibs, thumbnail_list, bbox_list, size_list, nInput=None, aoi_two_weight_filepath=None, **kwargs)[source]¶
-
wbia_cnn._plugin.
generate_thumbnail_class2_list
(ibs, thumbnail_list, nInput=None, classifier_two_weight_filepath=None, **kwargs)[source]¶
-
wbia_cnn._plugin.
generate_thumbnail_class_list
(ibs, thumbnail_list, nInput=None, classifier_weight_filepath=None, **kwargs)[source]¶
-
wbia_cnn._plugin.
get_verified_aid_pairs
(ibs)[source]¶ Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn.train import * # NOQA >>> import wbia >>> ibs = wbia.opendb('NNP_Master3') >>> verified_aid1_list, verified_aid2_list = get_verified_aid_pairs(ibs)
-
wbia_cnn._plugin.
non_max_suppression_fast
(box_list, conf_list, overlapThresh=0.5)[source]¶ Python version of Malisiewicz’s Matlab code: https://github.com/quantombone/exemplarsvm
NOTE: This is adapted from Pedro Felzenszwalb’s version (nms.m), but an inner loop has been eliminated to significantly speed it up in the case of a large number of boxes
Reference: https://github.com/rbgirshick/rcnn/blob/master/nms/nms.m Reference: http://www.pyimagesearch.com/2015/02/16/faster-non-maximum-suppression-python/
-
wbia_cnn._plugin.
test_convolutional
(model, image, patch_size='auto', stride='auto', padding=32, batch_size=None, verbose=False, confidence_thresh=0.5, **kwargs)[source]¶ Using a network, test an entire image full convolutionally
This function will test an entire image full convolutionally (or a close approximation of full convolutionally). The CUDA framework and driver is a limiting factor for how large an image can be given to a network for full convolutional inference. As a result, we implement a non-overlapping (or little overlapping) patch extraction approximation that processes the entire image within a single batch or very few batches. This is an extremely efficient process for processing an image with a CNN.
The patches are given a slight overlap in order to smooth the effects of boundary conditions, which are seen on every patch. We also mirror the border of each patch and add an additional amount of padding to cater to the architecture’s receptive field reduction.
See
utils.extract_patches_stride()
for patch extraction behavior.- Parameters
model (Model) – the network to use to perform feedforward inference
image (numpy.ndarray) – the image passed in to make a coreresponding sized dictionarf of response maps
patch_size (int, tuple of int, optional) – the size of the patches extracted across the image, passed in as a 2-tuple of (width, height). Defaults to (200, 200).
stride (int, tuple of int, optional) – the stride of the patches extracted across the image. Defaults to [patch_size - padding].
padding (int, optional) – the mirrored padding added to every patch during testing, which can be used to offset the effects of the receptive field reduction in the network. Defaults to 32.
**kwargs – arbitrary keyword arguments, passed to
model.test()
- Returns
- the number of total
samples used to generate the response map and the actual response maps themselves as a dictionary. The dictionary uses the class labels as the strings and the numpy array image as the values.
- Return type
samples, canvas_dict (tuple of int and dict)
-
wbia_cnn._plugin.
validate_annot_species_viewpoint_cnn
(ibs, aid_list, verbose=False)[source]¶ - Parameters
ibs (IBEISController) – ibeis controller object
aid_list (int) – list of annotation ids
verbose (bool) – verbosity flag(default = False)
- Returns
(bad_species_list, bad_viewpoint_list)
- Return type
tuple
- CommandLine:
python -m wbia_cnn._plugin –exec-validate_annot_species_viewpoint_cnn –db PZ_FlankHack python -m wbia_cnn._plugin –exec-validate_annot_species_viewpoint_cnn –db GZ_Master1
Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn._plugin import * # NOQA >>> import wbia >>> ibs = wbia.opendb(defaultdb='testdb1') >>> aid_list = ibs.get_valid_aids() >>> verbose = False >>> (bad_species_list, bad_viewpoint_list) = validate_annot_species_viewpoint_cnn(ibs, aid_list, verbose) >>> print('bad_species_list = %s' % (bad_species_list,)) >>> print('bad_species_list = %s' % (bad_viewpoint_list,)) >>> print(result)
- Ignore:
bad_viewpoint_list_ = [item for item in bad_viewpoint_list if item[2] is not None and item[0] > 1200] grouped_dict = ut.group_items(bad_viewpoint_list, ut.get_list_column(bad_viewpoint_list_, 3)) grouped_list = grouped_dict.values() regrouped_items = ut.flatten(ut.sortedby(grouped_list, map(len, grouped_list))) candidate_aid_list = ut.get_list_column(regrouped_items, 0) print(‘candidate_aid_list = %r’ % (candidate_aid_list,))
wbia_cnn._plugin_grabmodels module¶
wbia_cnn._version module¶
wbia_cnn.augment module¶
Core functions for data augmentation
References
https://github.com/benanne/kaggle-ndsb/blob/master/data.py
-
wbia_cnn.augment.
affine_perterb
(img, rng=<module 'numpy.random' from '/Users/jason.parham/virtualenv/wildme3.7/lib/python3.7/site-packages/numpy/random/__init__.py'>)[source]¶ - Parameters
img (ndarray[uint8_t, ndim=2]) – image data
rng (module) –
- Returns
img_warped
- Return type
ndarray
- CommandLine:
python -m wbia_cnn.augment –test-affine_perterb –show
Example
>>> # ENABLE_DOCTEST >>> from wbia_cnn.augment import * # NOQA >>> import vtool as vt >>> img_fpath = ut.grab_test_imgpath('carl.jpg') >>> img = vt.imread(img_fpath) >>> rng = np.random #.RandomState(0) >>> img_warped = affine_perterb(img, rng) >>> ut.quit_if_noshow() >>> import plottool as pt >>> pt.imshow(img_warped) >>> ut.show_if_requested()
-
wbia_cnn.augment.
augment_affine
(Xb, yb=None, rng=<module 'numpy.random' from '/Users/jason.parham/virtualenv/wildme3.7/lib/python3.7/site-packages/numpy/random/__init__.py'>, data_per_label=1, inplace=False, affperterb_ranges=None, aug_prop=0.5)[source]¶ - CommandLine:
python -m wbia_cnn.augment –test-augment_affine –show utprof.py -m wbia_cnn.augment –test-augment_affine
Example
>>> # ENABLE_DOCTEST >>> from wbia_cnn.augment import * # NOQA >>> from wbia_cnn.models import mnist >>> model, dataset = mnist.testdata_mnist() >>> X, y = dataset.subset('test') >>> batch_size = 1000 >>> Xb = (X[0:batch_size] / 255).astype(np.float32) >>> yb = y[0:batch_size] >>> rng = np.random.RandomState(0) >>> data_per_label = 1 >>> inplace = False >>> affperterb_ranges = dict( >>> zoom_range=(1.0, 1.3), >>> max_tx=2, >>> max_ty=2, >>> max_shear=TAU / 32, >>> max_theta=None, >>> enable_stretch=True, >>> enable_flip=False, >>> ) >>> Xb_, yb_ = augment_affine(Xb, yb, data_per_label=data_per_label, rng=rng, affperterb_ranges=affperterb_ranges) >>> assert Xb_ is not Xb >>> ut.quit_if_noshow() >>> import plottool as pt >>> pt.qt4ensure() >>> show_augmented_patches(Xb, Xb_, yb, yb_, data_per_label=data_per_label) >>> ut.show_if_requested()
-
wbia_cnn.augment.
augment_affine_siam
(Xb, yb=None, rng=<module 'numpy.random' from '/Users/jason.parham/virtualenv/wildme3.7/lib/python3.7/site-packages/numpy/random/__init__.py'>)[source]¶ - CommandLine:
python -m wbia_cnn.augment –test-augment_affine –show –db PZ_MTEST
Example
>>> # ENABLE_DOCTEST >>> from wbia_cnn.augment import * # NOQA >>> from wbia_cnn.models import mnist >>> model, dataset = mnist.testdata_mnist() >>> X, y = dataset.subset('test') >>> Xb = (X[0:8] / 255).astype(np.float32) >>> yb = y[0:8] >>> rng = np.random.RandomState(0) >>> Xb_, yb_ = augment_affine(Xb, yb, rng=rng) >>> import plottool as pt >>> pt.qt4ensure() >>> ut.quit_if_noshow() >>> show_augmented_patches(Xb, Xb_, yb, yb_) >>> ut.show_if_requested()
Example
>>> # ENABLE_DOCTEST >>> from wbia_cnn.augment import * # NOQA >>> from wbia_cnn import ingest_data, utils, draw_results >>> Xb_orig, yb_orig, Xb, yb = testdata_augment() >>> rng = np.random.RandomState(0) >>> Xb, yb = augment_affine(Xb, yb, rng=rng) >>> ut.quit_if_noshow() >>> show_augmented_patches(Xb_orig, Xb, yb_orig, yb) >>> ut.show_if_requested()
-
wbia_cnn.augment.
augment_gamma
(Xb, yb=None, rng=<module 'numpy.random' from '/Users/jason.parham/virtualenv/wildme3.7/lib/python3.7/site-packages/numpy/random/__init__.py'>)[source]¶ - CommandLine:
python -m wbia_cnn.augment –test-augment_gamma –show –db PZ_MTEST
Example
>>> # ENABLE_DOCTEST >>> from wbia_cnn.augment import * # NOQA >>> from wbia_cnn import ingest_data, utils, draw_results >>> Xb_orig, yb_orig, Xb, yb = testdata_augment() >>> rng = np.random.RandomState(0) >>> Xb, yb = augment_gamma(Xb, yb, rng=rng) >>> ut.quit_if_noshow() >>> show_augmented_patches(Xb_orig, Xb, yb_orig, yb) >>> ut.show_if_requested()
-
wbia_cnn.augment.
augment_shadow
(Xb, yb=None, rng=<module 'numpy.random' from '/Users/jason.parham/virtualenv/wildme3.7/lib/python3.7/site-packages/numpy/random/__init__.py'>, return_shadowmaps=False)[source]¶ - CommandLine:
python -m wbia_cnn.augment –test-augment_shadow –show –db PZ_MTEST
Example
>>> # ENABLE_DOCTEST >>> from wbia_cnn.augment import * # NOQA >>> from wbia_cnn import ingest_data, utils, draw_results >>> Xb_orig, yb_orig, Xb, yb = testdata_augment() >>> rng = np.random.RandomState(0) >>> Xb, yb, shadows = augment_shadow(Xb, yb, rng=rng, return_shadowmaps=True) >>> ut.quit_if_noshow() >>> show_augmented_patches(Xb_orig, Xb, yb_orig, yb, shadows) >>> ut.show_if_requested()
-
wbia_cnn.augment.
augment_siamese_patches
(Xb, yb=None, rng=<module 'numpy.random' from '/Users/jason.parham/virtualenv/wildme3.7/lib/python3.7/site-packages/numpy/random/__init__.py'>)[source]¶ - CommandLine:
python -m wbia_cnn.augment –test-augment_siamese_patches –show
Example
>>> # ENABLE_DOCTEST >>> from wbia_cnn.augment import * # NOQA >>> from wbia_cnn import ingest_data, utils, draw_results >>> data, labels = ingest_data.testdata_patchmatch() >>> cv2_data = utils.convert_theano_images_to_cv2_images(data) >>> batch_size = 128 >>> Xb, yb = cv2_data[0:batch_size], labels[0:batch_size // 2] >>> Xb1, yb1 = augment_siamese_patches(Xb.copy(), yb.copy()) >>> modified_indexes = np.where((Xb1 != Xb).sum(-1).sum(-1).sum(-1) > 0)[0] >>> ut.quit_if_noshow() >>> import plottool as pt >>> #z = draw_results.get_sample_pairimg_from_X(Xb, 1) >>> pt.imshow(Xb[modified_indexes[0]], pnum=(2, 2, 1), title='before') >>> pt.imshow(Xb1[modified_indexes[0]], pnum=(2, 2, 2), title='after') >>> pt.imshow(Xb[modified_indexes[1]], pnum=(2, 2, 3)) >>> pt.imshow(Xb1[modified_indexes[1]], pnum=(2, 2, 4)) >>> ut.show_if_requested()
-
wbia_cnn.augment.
augment_siamese_patches2
(Xb, yb=None, rng=<module 'numpy.random' from '/Users/jason.parham/virtualenv/wildme3.7/lib/python3.7/site-packages/numpy/random/__init__.py'>)[source]¶ - CommandLine:
python -m wbia_cnn.augment –test-augment_siamese_patches2 –show –db=PZ_MTEST python -m wbia_cnn.augment –test-augment_siamese_patches2 –show –colorspace=’bgr’
# Shows what augumentation looks like durring trainging python -m wbia_cnn.train –test-pz_patchmatch –ds pzmtest –weights=new –arch=siaml2 –train –monitor –DEBUG_AUGMENTATION
Example
>>> # ENABLE_DOCTEST >>> from wbia_cnn.augment import * # NOQA >>> from wbia_cnn import ingest_data, utils, draw_results >>> Xb_orig, yb_orig, Xb, yb = testdata_augment() >>> rng = np.random.RandomState(0) >>> Xb, yb = augment_siamese_patches2(Xb, yb, rng=rng) >>> ut.quit_if_noshow() >>> show_augmented_patches(Xb_orig, Xb, yb_orig, yb) >>> ut.show_if_requested()
-
wbia_cnn.augment.
random_affine_args
(zoom_range=(0.9090909090909091, 1.1), max_tx=1.0, max_ty=1.0, max_shear=0.39269908169872414, max_theta=0.19634954084936207, enable_flip=False, enable_stretch=False, rng=<module 'numpy.random' from '/Users/jason.parham/virtualenv/wildme3.7/lib/python3.7/site-packages/numpy/random/__init__.py'>)[source]¶ - CommandLine:
python -m wbia_cnn.augment –test-random_affine_args
Example
>>> # ENABLE_DOCTEST >>> from wbia_cnn.augment import * # NOQA >>> import vtool as vt >>> zoom_range = (0.9090909090909091, 1.1) >>> max_tx = 4 >>> max_ty = 4 >>> max_shear = np.pi >>> enable_rotate = True >>> enable_flip = True >>> enable_stretch = True >>> rng = np.random.RandomState(0) >>> affine_args = random_affine_args(zoom_range, max_tx, max_ty, max_shear, enable_rotate, enable_flip, enable_stretch, rng) >>> sx, sy, theta, shear, tx, ty = affine_args >>> Aff = vt.affine_mat3x3(sx, sy, theta, shear, tx, ty) >>> result = ut.numpy_str2(Aff) >>> print(result) np.array([[ 0.972, 0.566, 0.359], [ 0.308, 0.848, -0.611], [ 0. , 0. , 1. ]])
-
wbia_cnn.augment.
show_augmented_patches
(Xb, Xb_, yb, yb_, data_per_label=1, shadows=None)[source]¶ from wbia_cnn.augment import * # NOQA std_ = center_std mean_ = center_mean
wbia_cnn.batch_processing module¶
-
wbia_cnn.batch_processing.
augment_batch
(model, Xb, yb, batch_index, verbose, num_batches)[source]¶ Make sure to augment data in 0-1 space. This means use a mean fill values not 0.
>>> from wbia_cnn import augment >>> import plottool as pt >>> pt.qt4ensure() >>> augment.show_augmented_patches(Xb_orig, Xb, yb_orig, yb)
-
wbia_cnn.batch_processing.
batch_iterator
(model, X, y, randomize_batch_order=False, augment_on=False, X_is_cv2_native=True, verbose=None, lbl='verbose batch iteration')[source]¶ Breaks up data into to batches defined by model batch size
- CommandLine:
python -m wbia_cnn –tf batch_iterator:0 python -m wbia_cnn –tf batch_iterator:1 python -m wbia_cnn –tf batch_iterator:2 python -m wbia_cnn –tf batch_iterator:1 –DEBUG_AUGMENTATION
python -m wbia_cnn –tf batch_iterator:1 –noaugment # Threaded buffering seems to help a lot python -m wbia_cnn –tf batch_iterator:1 –augment
- Example0:
>>> # ENABLE_DOCTEST >>> from wbia_cnn.batch_processing import * # NOQA >>> from wbia_cnn import models >>> model = models.DummyModel(batch_size=16) >>> X, y = model.make_random_testdata(num=99, seed=None, cv2_format=True) >>> model.ensure_data_params(X, y) >>> y = None >>> encoder = None >>> randomize_batch_order = True >>> result_list = [(Xb, Yb) for Xb, Yb in batch_iterator(model, X, y, ... randomize_batch_order)] >>> result = ut.depth_profile(result_list, compress_consecutive=True) >>> print(result) [[(16, 1, 4, 4), 16]] * 6 + [[(3, 1, 4, 4), 3]]
- Example1:
>>> # ENABLE_DOCTEST >>> from wbia_cnn.batch_processing import * # NOQA >>> from wbia_cnn import models >>> import time >>> model = models.SiameseL2(batch_size=128, data_shape=(8, 8, 1)) >>> X, y = model.make_random_testdata(num=1000, seed=None, cv2_format=True) >>> model.ensure_data_params(X, y) >>> encoder = None >>> result_list1 = [] >>> result_list2 = [] >>> augment_on=not ut.get_argflag('--noaugment') >>> iterkw = dict(randomize_batch_order=True, >>> augment_on=augment_on, >>> showprog=True, verbose=ut.VERBOSE) >>> sleep_time = .05 >>> inside_time1 = 0 >>> inside_time2 = 0 >>> with ut.Timer('buffered') as t2: >>> generator = batch_iterator(model, X, y, **iterkw) >>> for Xb, Yb in ut.buffered_generator(generator, buffer_size=3): >>> with ut.Timer('Inside', verbose=False) as t: >>> time.sleep(sleep_time) >>> result_list2.append(Xb.shape) >>> inside_time2 += t.ellapsed >>> with ut.Timer('unbuffered') as t1: >>> generator = batch_iterator(model, X, y, **iterkw) >>> for Xb, Yb in generator: >>> with ut.Timer('Inside', verbose=False) as t: >>> time.sleep(sleep_time) >>> result_list1.append(Xb.shape) >>> inside_time1 += t.ellapsed >>> print('\nInside times should be the same') >>> print('inside_time1 = %r' % (inside_time1,)) >>> print('inside_time2 = %r' % (inside_time2,)) >>> print('Outside times show the overhead of data augmentation') >>> print('Overhead Unbuffered = %r' % (t1.ellapsed - inside_time1,)) >>> print('Overhead Buffered = %r' % (t2.ellapsed - inside_time2,)) >>> print('Efficiency Unbuffered = %.2f' % (100 * inside_time1 / t1.ellapsed,)) >>> print('Efficiency Buffered = %.2f' % (100 * inside_time2 / t2.ellapsed,)) >>> assert result_list1 == result_list2 >>> print(len(result_list2))
- Example2:
>>> # DISABLE_DOCTEST >>> from wbia_cnn.batch_processing import * # NOQA >>> from wbia_cnn.models.mnist import MNISTModel >>> from wbia_cnn import ingest_data >>> # should yield float32 regardlesss of original format >>> ut.exec_funckw(batch_iterator, globals()) >>> randomize_batch_order = False >>> # --- >>> dataset1 = ingest_data.grab_mnist_category_dataset_float() >>> model1 = MNISTModel(batch_size=8, data_shape=dataset1.data_shape, >>> output_dims=dataset1.output_dims, >>> arch_tag=dataset1.alias_key, >>> training_dpath=dataset1.training_dpath) >>> X1, y1 = dataset1.subset('train') >>> model1.ensure_data_params(X1, y1) >>> _iter1 = batch_iterator(model1, X1, y1, randomize_batch_order) >>> Xb1, yb1 = six.next(_iter1) >>> # --- >>> dataset2 = ingest_data.grab_mnist_category_dataset() >>> model2 = MNISTModel(batch_size=8, data_shape=dataset2.data_shape, >>> output_dims=dataset2.output_dims, >>> arch_tag=dataset2.alias_key, >>> training_dpath=dataset2.training_dpath) >>> X2, y2 = dataset2.subset('train') >>> model2.ensure_data_params(X2, y2) >>> _iter2 = batch_iterator(model2, X2, y2, randomize_batch_order) >>> Xb2, yb2 = six.next(_iter2) >>> # --- >>> X, y, model = X1, y1, model1 >>> assert np.all(yb2 == yb2) >>> # The uint8 and float32 data should produce similar values >>> # For this mnist set it will be a bit more off because the >>> # original uint8 scaling value was 256 not 255. >>> assert (Xb1[0] - Xb2[0]).max() < .1 >>> assert np.isclose(Xb1.mean(), 0, atol=.01) >>> assert np.isclose(Xb2.mean(), 0, atol=.01) >>> assert Xb1.max() < 1.0 and Xb2.max() < 1.0, 'out of (-1, 1)' >>> assert Xb1.min() > -1.0 and Xb1.min() > -1.0, 'out of (-1, 1)' >>> assert Xb1.min() < 0, 'should have some negative values' >>> assert Xb2.min() < 0, 'should have some negative values' >>> assert Xb1.max() > 0, 'should have some positive values' >>> assert Xb2.max() > 0, 'should have some positive values'
-
wbia_cnn.batch_processing.
concatenate_hack
(sequence, axis=0)[source]¶ Hack to fix numpy bug. concatenate fails when one item in sequence is empty
>>> sequence = (np.array([[]]), np.array([[1, 2, 3]])) >>> sequence = (np.array([[1, 2, 3]]), np.array([[]]))
-
wbia_cnn.batch_processing.
process_batch
(model, X, y, theano_fn, fix_output=False, buffered=False, show=False, spatial=False, showprog=True, **kwargs)[source]¶ Compute the loss over all training batches. Passes data to function that splits it into batches and appropriately preproecsses the data. Then this function sends that data to theano. Then the results are packaged up nicely before returning.
- CommandLine:
python -m wbia_cnn –tf process_batch –verbose python -m wbia_cnn –tf process_batch:0 –verbose python -m wbia_cnn –tf process_batch:1 –verbose
- Example0:
>>> # ENABLE_DOCTEST >>> from wbia_cnn.batch_processing import * # NOQA >>> from wbia_cnn import models >>> model = models.DummyModel(batch_size=128) >>> X, y = model.make_random_testdata(num=2000, seed=None) >>> model.init_arch() >>> theano_fn = model.build_predict_func() >>> kwargs = {'X_is_cv2_native': False, 'showprog': True, ... 'randomize_batch_order': True} >>> outputs_ = process_batch(model, X, y, theano_fn, **kwargs) >>> result = ut.dict_str(outputs_) >>> print(result)
- Example0:
>>> # ENABLE_DOCTEST >>> from wbia_cnn.batch_processing import * # NOQA >>> from wbia_cnn import models >>> model = models.SiameseL2(batch_size=128, data_shape=(32, 32, 1), ... strict_batch_size=True) >>> X, y = model.make_random_testdata(num=2000, seed=None) >>> model.init_arch() >>> theano_fn = model.build_predict_func() >>> kwargs = {'X_is_cv2_native': False, 'showprog': True, ... 'randomize_batch_order': True} >>> outputs_ = process_batch(model, X, y, theano_fn, **kwargs) >>> result = ut.dict_str(outputs_) >>> print(result)
- Ignore:
Xb, yb = batch_iter.next() assert Xb.shape == (8, 1, 4, 4) yb.shape == (8,)
- Ignore:
X, y = model.make_random_testdata(num=2000, seed=None) kwargs = {‘X_is_cv2_native’: False, ‘showprog’: True,
‘randomize_batch_order’: True, ‘time_thresh’: .5, }
print(‘Testing Unbuffered’) batch_iter = batch_iterator(model, X, y, lbl=theano_fn.name, **kwargs) for Xb, yb in ut.ProgressIter(batch_iter, lbl=’:EXEC FG’):
[ut.is_prime(346373) for _ in range(2)]
# Notice how the progress iters are not interlaced like # they are in the unbuffered version import sys sys.stdout.flush() print(‘Testing Buffered’) sys.stdout.flush() batch_iter2 = batch_iterator(model, X, y, lbl=theano_fn.name, **kwargs) batch_iter2 = ut.buffered_generator(batch_iter2, buffer_size=4) print(‘Iterating’) for Xb, yb in ut.ProgressIter(batch_iter2, lbl=’:EXEC FG’):
[ut.is_prime(346373) for _ in range(2)]
wbia_cnn.custom_layers module¶
-
class
wbia_cnn.custom_layers.
BatchNormLayer2
(incoming, nonlinearity=None, **kwargs)[source]¶ Bases:
Lasagne.lasagne.layers.normalization.BatchNormLayer
Adds a nonlinearity to batch norm layer to reduce number of layers
-
get_output_for
(input, **kwargs)[source]¶ Propagates the given input through this layer (and only this layer).
- Parameters
input (Theano expression) – The expression to propagate through this layer.
- Returns
output – The output of this layer given the input to this layer.
- Return type
Theano expression
Notes
This is called by the base
lasagne.layers.get_output()
to propagate data through a network.This method should be overridden when implementing a new
Layer
class. By default it raises NotImplementedError.
-
-
class
wbia_cnn.custom_layers.
CenterSurroundLayer
(input_layer, *args, **kwargs)[source]¶ Bases:
Lasagne.lasagne.layers.base.Layer
-
get_output_for
(input_expr, T=<module 'theano.tensor' from '/Users/jason.parham/virtualenv/wildme3.7/lib/python3.7/site-packages/Theano-1.0.5-py3.7.egg/theano/tensor/__init__.py'>, **kwargs)[source]¶ - CommandLine:
python -m wbia_cnn.custom_layers –test-CenterSurroundLayer.get_output_for:0 –show python -m wbia_cnn.custom_layers –test-CenterSurroundLayer.get_output_for:1 –show
- Example0:
>>> # DISABLE_DOCTEST >>> from wbia_cnn.custom_layers import * # NOQA >>> import theano >>> #item_shape = (32, 32, 3) >>> item_shape = (41, 41, 3) >>> self, inputdata_ = testdata_centersurround(item_shape) >>> # Test the actual symbolic expression >>> output_T = utils.evaluate_symbolic_layer(self.get_output_for, inputdata_, T.tensor4, T=theano.tensor) >>> output_T = output_T.astype(np.uint8) >>> ut.quit_if_noshow() >>> img_list = utils.convert_theano_images_to_cv2_images(output_T) >>> interact_image_list(img_list, num_per_page=8)
- Example1:
>>> # DISABLE_DOCTEST >>> from wbia_cnn.custom_layers import * # NOQA >>> import numpy as np >>> #item_shape = (32, 32, 3) >>> item_shape = (41, 41, 3) >>> self, input_expr = testdata_centersurround(item_shape) >>> # Test using just numpy >>> output_np = self.get_output_for(input_expr, T=np) >>> print('results agree') >>> ut.quit_if_noshow() >>> img_list = utils.convert_theano_images_to_cv2_images(output_np) >>> interact_image_list(img_list, num_per_page=8)
- Ignore:
from wbia_cnn import draw_net #draw_net.draw_theano_symbolic_expression(result) assert np.all(output_np == output_T) np.stack = np.vstack T = np
-
get_output_shape_for
(input_shape)[source]¶ Computes the output shape of this layer, given an input shape.
- Parameters
input_shape (tuple) – A tuple representing the shape of the input. The tuple should have as many elements as there are input dimensions, and the elements should be integers or None.
- Returns
A tuple representing the shape of the output of this layer. The tuple has as many elements as there are output dimensions, and the elements are all either integers or None.
- Return type
tuple
Notes
This method will typically be overridden when implementing a new
Layer
class. By default it simply returns the input shape. This means that a layer that does not modify the shape (e.g. because it applies an elementwise operation) does not need to override this method.
-
-
class
wbia_cnn.custom_layers.
CyclicPoolLayer
(input_layer, pool_function=<function mean>)[source]¶ Bases:
Lasagne.lasagne.layers.base.Layer
Utility layer that unfolds the viewpoints dimension and pools over it. Note that this only makes sense for dense representations, not for feature maps (because no inverse transforms are applied to align them).
-
get_output_for
(input_, *args, **kwargs)[source]¶ Propagates the given input through this layer (and only this layer).
- Parameters
input (Theano expression) – The expression to propagate through this layer.
- Returns
output – The output of this layer given the input to this layer.
- Return type
Theano expression
Notes
This is called by the base
lasagne.layers.get_output()
to propagate data through a network.This method should be overridden when implementing a new
Layer
class. By default it raises NotImplementedError.
-
get_output_shape_for
(input_shape)[source]¶ Computes the output shape of this layer, given an input shape.
- Parameters
input_shape (tuple) – A tuple representing the shape of the input. The tuple should have as many elements as there are input dimensions, and the elements should be integers or None.
- Returns
A tuple representing the shape of the output of this layer. The tuple has as many elements as there are output dimensions, and the elements are all either integers or None.
- Return type
tuple
Notes
This method will typically be overridden when implementing a new
Layer
class. By default it simply returns the input shape. This means that a layer that does not modify the shape (e.g. because it applies an elementwise operation) does not need to override this method.
-
-
class
wbia_cnn.custom_layers.
FlipLayer
(incoming, name=None)[source]¶ Bases:
Lasagne.lasagne.layers.base.Layer
-
get_output_for
(input, **kwargs)[source]¶ Propagates the given input through this layer (and only this layer).
- Parameters
input (Theano expression) – The expression to propagate through this layer.
- Returns
output – The output of this layer given the input to this layer.
- Return type
Theano expression
Notes
This is called by the base
lasagne.layers.get_output()
to propagate data through a network.This method should be overridden when implementing a new
Layer
class. By default it raises NotImplementedError.
-
get_output_shape_for
(input_shape)[source]¶ Computes the output shape of this layer, given an input shape.
- Parameters
input_shape (tuple) – A tuple representing the shape of the input. The tuple should have as many elements as there are input dimensions, and the elements should be integers or None.
- Returns
A tuple representing the shape of the output of this layer. The tuple has as many elements as there are output dimensions, and the elements are all either integers or None.
- Return type
tuple
Notes
This method will typically be overridden when implementing a new
Layer
class. By default it simply returns the input shape. This means that a layer that does not modify the shape (e.g. because it applies an elementwise operation) does not need to override this method.
-
-
class
wbia_cnn.custom_layers.
L1DistanceLayer
(input_layer, *args, **kwargs)[source]¶ Bases:
Lasagne.lasagne.layers.base.Layer
-
get_output_for
(input_, *args, **kwargs)[source]¶ Propagates the given input through this layer (and only this layer).
- Parameters
input (Theano expression) – The expression to propagate through this layer.
- Returns
output – The output of this layer given the input to this layer.
- Return type
Theano expression
Notes
This is called by the base
lasagne.layers.get_output()
to propagate data through a network.This method should be overridden when implementing a new
Layer
class. By default it raises NotImplementedError.
-
get_output_shape_for
(input_shape)[source]¶ Computes the output shape of this layer, given an input shape.
- Parameters
input_shape (tuple) – A tuple representing the shape of the input. The tuple should have as many elements as there are input dimensions, and the elements should be integers or None.
- Returns
A tuple representing the shape of the output of this layer. The tuple has as many elements as there are output dimensions, and the elements are all either integers or None.
- Return type
tuple
Notes
This method will typically be overridden when implementing a new
Layer
class. By default it simply returns the input shape. This means that a layer that does not modify the shape (e.g. because it applies an elementwise operation) does not need to override this method.
-
-
class
wbia_cnn.custom_layers.
L1NormalizeLayer
(input_layer, *args, **kwargs)[source]¶ Bases:
Lasagne.lasagne.layers.base.Layer
-
get_output_for
(input_, *args, **kwargs)[source]¶ Propagates the given input through this layer (and only this layer).
- Parameters
input (Theano expression) – The expression to propagate through this layer.
- Returns
output – The output of this layer given the input to this layer.
- Return type
Theano expression
Notes
This is called by the base
lasagne.layers.get_output()
to propagate data through a network.This method should be overridden when implementing a new
Layer
class. By default it raises NotImplementedError.
-
-
class
wbia_cnn.custom_layers.
L2NormalizeLayer
(input_layer, axis=1, **kwargs)[source]¶ Bases:
Lasagne.lasagne.layers.base.Layer
Normalizes the outputs of a layer to have an L2 norm of 1. This is useful for siamese networks who’s outputs will be comparsed using the L2 distance.
-
get_output_for
(input_, axis=None, T=<module 'theano.tensor' from '/Users/jason.parham/virtualenv/wildme3.7/lib/python3.7/site-packages/Theano-1.0.5-py3.7.egg/theano/tensor/__init__.py'>, **kwargs)[source]¶ - CommandLine:
python -m wbia_cnn.custom_layers –test-L2NormalizeLayer.get_output_for
- Example0:
>>> # ENABLE_DOCTEST >>> from wbia_cnn.custom_layers import * # NOQA >>> # l2 normalization on batches of vector encodings >>> input_layer = testdata_input_layer(item_shape=(8,), batch_size=4) >>> inputdata_ = np.random.rand(*input_layer.shape).astype(np.float32) >>> axis = 1 >>> self = L2NormalizeLayer(input_layer, axis=axis) >>> # Test numpy version >>> T = np >>> input_ = inputdata_ >>> output_np = self.get_output_for(inputdata_, T=np) >>> assert np.all(np.isclose(np.linalg.norm(output_np, axis=axis), 1.0)) >>> # Test theano version >>> T = theano.tensor >>> input_expr = input_ = T.matrix(name='vector_input') >>> output_expr = self.get_output_for(input_expr, T=T) >>> output_T = output_expr.eval({input_expr: inputdata_}) >>> print(output_T) >>> assert np.all(np.isclose(output_T, output_np)), 'theano and numpy diagree'
- Example1:
>>> # ENABLE_DOCTEST >>> from wbia_cnn.custom_layers import * # NOQA >>> # l2 normalization on batches of image filters >>> input_layer = testdata_input_layer(item_shape=(3, 2, 2), batch_size=4) >>> inputdata_ = np.random.rand(*input_layer.shape).astype(np.float32) >>> axis = 2 >>> self = L2NormalizeLayer(input_layer, axis=axis) >>> # Test numpy version >>> T = np >>> input_ = inputdata_ >>> output_np = self.get_output_for(inputdata_, T=np) >>> output_flat_np = output_np.reshape(np.prod(input_layer.shape[0:2]), np.prod(input_layer.shape[2:4])) >>> assert np.all(np.isclose(np.linalg.norm(output_flat_np, axis=1), 1.0)) >>> # Test theano version >>> T = theano.tensor >>> input_expr = input_ = T.tensor4(name='image_filter_input') >>> output_expr = self.get_output_for(input_expr, T=T) >>> output_T = output_expr.eval({input_expr: inputdata_}) >>> print(output_T) >>> assert np.all(np.isclose(output_T, output_np)), 'theano and numpy diagree' >>> #output_T = utils.evaluate_symbolic_layer(self.get_output_for, inputdata_, T.tensor4, T=theano.tensor)
-
-
class
wbia_cnn.custom_layers.
L2SquaredDistanceLayer
(input_layer, *args, **kwargs)[source]¶ Bases:
Lasagne.lasagne.layers.base.Layer
-
get_output_for
(input_, *args, **kwargs)[source]¶ Propagates the given input through this layer (and only this layer).
- Parameters
input (Theano expression) – The expression to propagate through this layer.
- Returns
output – The output of this layer given the input to this layer.
- Return type
Theano expression
Notes
This is called by the base
lasagne.layers.get_output()
to propagate data through a network.This method should be overridden when implementing a new
Layer
class. By default it raises NotImplementedError.
-
get_output_shape_for
(input_shape)[source]¶ Computes the output shape of this layer, given an input shape.
- Parameters
input_shape (tuple) – A tuple representing the shape of the input. The tuple should have as many elements as there are input dimensions, and the elements should be integers or None.
- Returns
A tuple representing the shape of the output of this layer. The tuple has as many elements as there are output dimensions, and the elements are all either integers or None.
- Return type
tuple
Notes
This method will typically be overridden when implementing a new
Layer
class. By default it simply returns the input shape. This means that a layer that does not modify the shape (e.g. because it applies an elementwise operation) does not need to override this method.
-
-
class
wbia_cnn.custom_layers.
LocallyConnected2DLayer
(incoming, num_filters, filter_size, stride=(1, 1), pad=0, untie_biases=False, W=<Lasagne.lasagne.init.GlorotUniform object>, b=<Lasagne.lasagne.init.Constant object>, nonlinearity=<function rectify>, convolution=<function conv2d>, **kwargs)[source]¶ Bases:
Lasagne.lasagne.layers.base.Layer
Copy of the Conv2D layer that needs to be adapted into a locally connected layer
- Parameters
incoming (layers.Layer) –
num_filters –
filter_size –
stride (tuple) – (default = (1, 1))
pad (int) – (default = 0)
untie_biases (bool) – (default = False)
W (GlorotUniform) – (default = <init.GlorotUniform object at 0x7f551a3537d0>)
b (Constant) – (default = <init.Constant object at 0x7f551a33ecd0>)
nonlinearity (function) – (default = <function rectify at 0x7f55307989b0>)
convolution (function) – (default = <function conv2d at 0x7f55330148c0>)
- CommandLine:
python -m wbia_cnn.custom_layers –exec-__init__
Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn.custom_layers import * # NOQA >>> incoming = testdata_input_layer(item_shape=(3,8,8), batch_size=4) >>> num_filters = 64 >>> filter_size = (3, 3) >>> stride = (1, 1) >>> pad = 0 >>> untie_biases = False >>> W = init.GlorotUniform() >>> b = init.Constant(0.) >>> nonlinearity = nonlinearities.rectify >>> convolution = T.nnet.conv2d >>> self = LocallyConnected2DLayer(incoming, num_filters, filter_size, >>> stride, pad, untie_biases, W, b, >>> nonlinearity, convolution)
- Ignore:
self.get_output_rc(self.input_shape)
-
get_W_shape
()[source]¶ Get the shape of the weight matrix W.
- Returns
The shape of the weight matrix.
(should have a different conv matrix for each output node) (ie NO WEIGHT SHARING)
- Return type
tuple of int
-
get_output_for
(input, input_shape=None, **kwargs)[source]¶ Propagates the given input through this layer (and only this layer).
- Parameters
input (Theano expression) – The expression to propagate through this layer.
- Returns
output – The output of this layer given the input to this layer.
- Return type
Theano expression
Notes
This is called by the base
lasagne.layers.get_output()
to propagate data through a network.This method should be overridden when implementing a new
Layer
class. By default it raises NotImplementedError.
-
get_output_shape_for
(input_shape)[source]¶ Computes the output shape of this layer, given an input shape.
- Parameters
input_shape (tuple) – A tuple representing the shape of the input. The tuple should have as many elements as there are input dimensions, and the elements should be integers or None.
- Returns
A tuple representing the shape of the output of this layer. The tuple has as many elements as there are output dimensions, and the elements are all either integers or None.
- Return type
tuple
Notes
This method will typically be overridden when implementing a new
Layer
class. By default it simply returns the input shape. This means that a layer that does not modify the shape (e.g. because it applies an elementwise operation) does not need to override this method.
-
rrr
(verbose=True, reload_module=True)¶ special class reloading function This function is often injected as rrr of classes
-
class
wbia_cnn.custom_layers.
MaxPool2DLayer
(incoming, pool_size, stride=None, pad=0, 0, ignore_border=True, **kwargs)[source]¶ Bases:
Lasagne.lasagne.layers.pool.Pool2DLayer
2D max-pooling layer
Performs 2D max-pooling over the two trailing axes of a 4D input tensor.
- Parameters
incoming (a
Layer
instance or tuple) – The layer feeding into this layer, or the expected input shape.pool_size (integer or iterable) – The length of the pooling region in each dimension. If an integer, it is promoted to a square pooling region. If an iterable, it should have two elements.
stride (integer, iterable or
None
) – The strides between sucessive pooling regions in each dimension. IfNone
thenstride = pool_size
.pad (integer or iterable) – Number of elements to be added on each side of the input in each dimension. Each value must be less than the corresponding stride.
ignore_border (bool) – If
True
, partial pooling regions will be ignored. Must beTrue
ifpad != (0, 0)
.**kwargs – Any additional keyword arguments are passed to the
Layer
superclass.
Notes
The value used to pad the input is chosen to be less than the minimum of the input, so that the output of each pooling region always corresponds to some element in the unpadded input region.
Using
ignore_border=False
prevents Theano from using cuDNN for the operation, so it will fall back to a slower implementation.
-
class
wbia_cnn.custom_layers.
MultiImageRollLayer
(input_layer)[source]¶ Bases:
Lasagne.lasagne.layers.base.Layer
orig CyclicConvRollLayer
This layer turns (n_views * batch_size, num_channels, r, c) into (n_views * batch_size, n_views * num_channels, r, c) by rolling and concatenating feature maps. It also applies the correct inverse transforms to the r and c dimensions to align the feature maps.
References
https://github.com/benanne/kaggle-ndsb/blob/master/dihedral.py#L224
-
get_output_for
(input_, *args, **kwargs)[source]¶ Propagates the given input through this layer (and only this layer).
- Parameters
input (Theano expression) – The expression to propagate through this layer.
- Returns
output – The output of this layer given the input to this layer.
- Return type
Theano expression
Notes
This is called by the base
lasagne.layers.get_output()
to propagate data through a network.This method should be overridden when implementing a new
Layer
class. By default it raises NotImplementedError.
-
get_output_shape_for
(input_shape)[source]¶ Computes the output shape of this layer, given an input shape.
- Parameters
input_shape (tuple) – A tuple representing the shape of the input. The tuple should have as many elements as there are input dimensions, and the elements should be integers or None.
- Returns
A tuple representing the shape of the output of this layer. The tuple has as many elements as there are output dimensions, and the elements are all either integers or None.
- Return type
tuple
Notes
This method will typically be overridden when implementing a new
Layer
class. By default it simply returns the input shape. This means that a layer that does not modify the shape (e.g. because it applies an elementwise operation) does not need to override this method.
-
-
class
wbia_cnn.custom_layers.
MultiImageSliceLayer
(input_layer)[source]¶ Bases:
Lasagne.lasagne.layers.base.Layer
orig CyclicSliceLayer .. rubric:: References
https://github.com/benanne/kaggle-ndsb/blob/master/dihedral.py#L89
This layer stacks rotations of 0, 90, 180, and 270 degrees of the input along the batch dimension. If the input has shape (batch_size, num_channels, r, c), then the output will have shape (4 * batch_size, num_channels, r, c). Note that the stacking happens on axis 0, so a reshape to (4, batch_size, num_channels, r, c) will separate the slice axis.
-
get_output_for
(input_, *args, **kwargs)[source]¶ Propagates the given input through this layer (and only this layer).
- Parameters
input (Theano expression) – The expression to propagate through this layer.
- Returns
output – The output of this layer given the input to this layer.
- Return type
Theano expression
Notes
This is called by the base
lasagne.layers.get_output()
to propagate data through a network.This method should be overridden when implementing a new
Layer
class. By default it raises NotImplementedError.
-
get_output_shape_for
(input_shape)[source]¶ Computes the output shape of this layer, given an input shape.
- Parameters
input_shape (tuple) – A tuple representing the shape of the input. The tuple should have as many elements as there are input dimensions, and the elements should be integers or None.
- Returns
A tuple representing the shape of the output of this layer. The tuple has as many elements as there are output dimensions, and the elements are all either integers or None.
- Return type
tuple
Notes
This method will typically be overridden when implementing a new
Layer
class. By default it simply returns the input shape. This means that a layer that does not modify the shape (e.g. because it applies an elementwise operation) does not need to override this method.
-
-
class
wbia_cnn.custom_layers.
SiameseConcatLayer
(input_layer, data_per_label=2, axis=1, **kwargs)[source]¶ Bases:
Lasagne.lasagne.layers.base.Layer
TODO checkout layers.merge.ConcatLayer
Takes two network representations in the batch and combines them along an axis.
-
get_output_for
(input_, T=<module 'theano.tensor' from '/Users/jason.parham/virtualenv/wildme3.7/lib/python3.7/site-packages/Theano-1.0.5-py3.7.egg/theano/tensor/__init__.py'>, **kwargs)[source]¶ - CommandLine:
python -m wbia_cnn.custom_layers –test-SiameseConcatLayer.get_output_for:1 –show
- Example0:
>>> # ENABLE_DOCTEST >>> from wbia_cnn.custom_layers import * # NOQA >>> input_shape = (128, 1024) >>> input_layer = layers.InputLayer(shape=input_shape) >>> self = SiameseConcatLayer(input_layer) >>> np.random.seed(0) >>> input_ = np.random.rand(*input_shape) >>> T = np >>> output_ = self.get_output_for(input_, T=T) >>> target_shape = self.get_output_shape_for(input_shape) >>> result = output_.shape >>> print(result) >>> assert target_shape == result (64, 2048)
- Example1:
>>> # DISABLE_DOCTEST >>> from wbia_cnn.custom_layers import * # NOQA >>> from wbia_cnn import utils >>> from wbia_cnn import draw_net >>> import theano >>> import numpy as np >>> input_layer = layers.InputLayer(shape=(4, 3, 32, 32)) >>> cs_layer = CenterSurroundLayer(input_layer) >>> # Make sure that this can concat center surround properly >>> self = SiameseConcatLayer(cs_layer, axis=2, data_per_label=4) >>> data = utils.testdata_imglist()[0] >>> inputdata_ = utils.convert_cv2_images_to_theano_images(data) >>> outputdata_ = cs_layer.get_output_for(inputdata_, T=np) >>> input_ = outputdata_ >>> output_ = self.get_output_for(input_, T=np) >>> ut.quit_if_noshow() >>> img_list = utils.convert_theano_images_to_cv2_images(output_) >>> interact_image_list(img_list, num_per_page=2)
-
get_output_shape_for
(input_shape, axis=None)[source]¶ - Parameters
input_shape – shape being fed into this layer
axis – overrideable for tests
- CommandLine:
python -m wbia_cnn.custom_layers –test-get_output_shape_for
- Example0:
>>> # ENABLE_DOCTEST >>> from wbia_cnn.custom_layers import * # NOQA >>> input_layer = testdata_input_layer(item_shape=(3, 8, 16)) >>> self = SiameseConcatLayer(input_layer) >>> input_shape = input_layer.shape >>> output_shape_list = [self.get_output_shape_for(input_shape, axis) for axis in [1, 2, 3, -3, -2, -1]] >>> result = str(output_shape_list[0:3]) + '\n' + str(output_shape_list[3:]) >>> print(result) [(64, 6, 8, 16), (64, 3, 16, 16), (64, 3, 8, 32)] [(64, 6, 8, 16), (64, 3, 16, 16), (64, 3, 8, 32)]
- Example1:
>>> # ENABLE_DOCTEST >>> from wbia_cnn.custom_layers import * # NOQA >>> input_layer = testdata_input_layer(item_shape=(1024,)) >>> self = SiameseConcatLayer(input_layer) >>> input_shape = input_layer.shape >>> output_shape_list = [self.get_output_shape_for(input_shape, axis) for axis in [1, -1]] >>> result = output_shape_list >>> print(result) [(64, 2048), (64, 2048)]
-
-
wbia_cnn.custom_layers.
evaluate_layer_list
(network_layers_def, verbose=None)[source]¶ compiles a sequence of partial functions into a network
-
wbia_cnn.custom_layers.
load_json_arch_def
(arch_json_fpath)[source]¶ layer_list = layers.get_all_layers(output_layer)
from wbia_cnn import net_strs layer_json_list = [net_strs.make_layer_json_dict(layer)
for layer in layer_list]
arch_json_fpath = ‘/media/raid/work/WS_ALL/_ibsdb/_ibeis_cache/nets/injur-shark_10056_224x224x3_auqbfhle/models/arch_injur-shark_o2_d11_c688_acioqbst/saved_sessions/fit_session_2016-08-26T173854+5/fit_arch_info.json’
wbia_cnn.dataset module¶
-
class
wbia_cnn.dataset.
DataSet
(cfgstr=None, training_dpath='.', data_shape=None, num_data=None, name=None, ext='.pkl')[source]¶ Bases:
utool.util_dev.NiceRepr
helper class for managing dataset paths and general metadata
- SeeAlso:
python -m wbia_cnn.ingest_data –test-get_wbia_part_siam_dataset –show
- CommandLine:
python -m wbia_cnn.dataset DataSet
Example
>>> from wbia_cnn.ingest_data import * # NOQA >>> dataset = grab_mnist_category_dataset() >>> dataset.print_dir_structure() >>> # ---- >>> from wbia_cnn.models import MNISTModel >>> model = MNISTModel(batch_size=128, data_shape=(24, 24, 1), >>> output_dims=10, dataset_dpath=dataset.dataset_dpath) >>> model.print_structure()
-
property
data
¶
-
property
data_fpath
¶
-
property
data_shape
¶
-
property
dataset_dpath
¶
-
property
dataset_id
¶
-
property
full_dpath
¶
-
property
hashid
¶
-
property
info_fpath
¶
-
interact
(key='full', **kwargs)[source]¶ python -m wbia_cnn –tf netrun –db mnist –ensuredata –show –datatype=category python -m wbia_cnn –tf netrun –db PZ_MTEST –acfg ctrl –ensuredata –show
-
property
labels
¶
-
property
labels_fpath
¶
-
property
metadata
¶
-
property
metadata_fpath
¶
-
rrr
(verbose=True, reload_module=True)¶ special class reloading function This function is often injected as rrr of classes
-
property
split_dpath
¶
-
property
unique_labels
¶
-
vd
()¶
-
wbia_cnn.dataset.
expand_data_indicies
(label_indices, data_per_label=1)[source]¶ when data_per_label > 1, gives the corresponding data indicies for the data indicies
-
wbia_cnn.dataset.
get_juction_dpath
()[source]¶ - Returns
junction_dpath
- Return type
str
- CommandLine:
python -m wbia_cnn –tf get_juction_dpath –show
Example
>>> # ENABLE_DOCTEST >>> from wbia_cnn.dataset import * # NOQA >>> junction_dpath = get_juction_dpath() >>> result = ('junction_dpath = %s' % (str(junction_dpath),)) >>> print(result) >>> ut.quit_if_noshow() >>> ut.vd(junction_dpath)
-
wbia_cnn.dataset.
stratified_kfold_label_split
(y, labels, n_folds=2, y_idx=None, rng=None)[source]¶ Also enforces that labels are not broken into separate groups.
- Parameters
y (ndarray) – labels
labels –
y_idx (array) – indexes associated with y if it was already presampled
rng (RandomState) – random number generator(default = None)
- Returns
index_sets
- Return type
?
- CommandLine:
python -m wbia_cnn.dataset stratified_label_shuffle_split –show
Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn.dataset import * # NOQA >>> y = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] >>> labels = [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 6, 0, 7, 7, 7, 7] >>> fractions = [.7, .3] >>> rng = np.random.RandomState(0) >>> index_sets = stratified_label_shuffle_split(y, labels, fractions, rng)
-
wbia_cnn.dataset.
stratified_label_shuffle_split
(y, labels, fractions, y_idx=None, rng=None)[source]¶ modified from sklearn to make n splits instaed of 2. Also enforces that labels are not broken into separate groups.
- Parameters
y (ndarray) – labels
labels –
fractions –
rng (RandomState) – random number generator(default = None)
- Returns
index_sets
- Return type
?
- CommandLine:
python -m wbia_cnn.dataset stratified_label_shuffle_split –show
Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn.dataset import * # NOQA >>> y = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] >>> labels = [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 6, 0, 7, 7, 7, 7] >>> fractions = [.7, .3] >>> rng = np.random.RandomState(0) >>> index_sets = stratified_label_shuffle_split(y, labels, fractions, rng)
wbia_cnn.draw_net module¶
Functions to create network diagrams from a list of Layers.
References
# Adapted from https://github.com/ebenolson/Lasagne/blob/master/examples/draw_net.py
# TODO: https://github.com/dnouri/nolearn/blob/master/nolearn/lasagne/visualize.py
-
class
wbia_cnn.draw_net.
Dream
(model, init='gauss', niters=100, update_rate=0.01, weight_decay=1e-05)[source]¶ Bases:
object
https://groups.google.com/forum/#!topic/lasagne-users/UxZpNthZfq0 http://arxiv.org/pdf/1312.6034.pdf http://igva2012.wikispaces.asu.edu/file/view/Erhan+2009+Visualizing+higher+layer+features+of+a+deep+network.pdf
#TODO https://arxiv.org/pdf/1605.09304v3.pdf
Class model visualization. Sort of like a deep-dream
- CommandLine:
python -m wbia_cnn.draw_net Dream –show
Example
>>> # DISABLE_DOCTEST >>> # Assumes mnist is trained >>> from wbia_cnn.draw_net import * # NOQA >>> from wbia_cnn.models import mnist >>> model, dataset = mnist.testdata_mnist(dropout=.5) >>> model.init_arch() >>> model.load_model_state() >>> target_labels = 3 >>> ut.quit_if_noshow() >>> import plottool as pt >>> #pt.qt4ensure() >>> dream = Dream(model, niters=200) >>> img = dream.make_class_images(target_labels) >>> pt.imshow(img) >>> ut.show_if_requested()
-
_make_init_state
()[source]¶ - CommandLine:
python -m wbia_cnn.draw_net _make_init_state –show
Example
>>> # DISABLE_DOCTEST >>> # Assumes mnist is trained >>> from wbia_cnn.draw_net import * # NOQA >>> from wbia_cnn.models import mnist >>> model, dataset = mnist.testdata_mnist(dropout=.5) >>> model.init_arch() >>> dream = Dream(model, init='rgauss', niters=200) >>> ut.quit_if_noshow() >>> import plottool as pt >>> import vtool as vt >>> #pt.qt4ensure() >>> initial_state = dream._make_init_state().transpose((0, 2, 3, 1))[0] >>> pt.imshow(initial_state, pnum=(1, 2, 1), fnum=1) >>> pt.imshow(vt.norm01(initial_state), pnum=(1, 2, 2), fnum=1) >>> ut.show_if_requested()
-
_make_objective
(shared_images, target_labels)[source]¶ The goal is to optimize S_c = score of class c before softmax nonlinearity argmax_{I} S_c(I) - lambda elltwo{I} max(S_c(I) - lambda * norm(I, 2))
-
generate_class_images
(target_labels)[source]¶ import plottool as pt fnum = None kw = dict(init=’gauss’, niters=500, update_rate=.05, weight_decay=1e-4) target_labels = list(range(model.output_dims)) dream = draw_net.Dream(model, **kw) target_labels = 8 images = list(dream.generate_class_images(target_labels))
vid = vt.make_video(images, ‘dynimg.pimj’, fps=1, is_color=False, format=’PIM1’) vid = vt.make_video2(images, ‘dynimg’)
import matplotlib.pyplot as plt ims = [] for img in imgs:
im = plt.imshow(img[:, :, 0], interpolation=’nearest’, cmap=’gray’) ims.append([im])
import matplotlib.animation as animation fig = plt.figure() ani = animation.ArtistAnimation(fig, ims, interval=50, blit=True,
repeat_delay=1000)
ani.save(‘dynamic_images.mp4’) ut.startfile(‘dynamic_images.mp4’) plt.show()
-
wbia_cnn.draw_net.
draw_neural_net
(ax, left, right, bottom, top, layer_sizes)[source]¶ References
# Taken from https://gist.github.com/craffel/2d727968c3aaebd10359
Draw a neural network cartoon using matplotilb.
Example
>>> fig = plt.figure(figsize=(12, 12)) >>> draw_neural_net(fig.gca(), .1, .9, .1, .9, [4, 7, 2])
- Parameters
- axmatplotlib.axes.AxesSubplot
The axes on which to plot the cartoon (get e.g. by plt.gca())
- leftfloat
The center of the leftmost node(s) will be placed here
- rightfloat
The center of the rightmost node(s) will be placed here
- bottomfloat
The center of the bottommost node(s) will be placed here
- topfloat
The center of the topmost node(s) will be placed here
- layer_sizeslist of int
List of layer sizes, including input and output dimensionality
-
wbia_cnn.draw_net.
make_conv_weight_image
(all_weights, limit=144)[source]¶ just makes the image ndarray of the weights
-
wbia_cnn.draw_net.
occlusion_heatmap
(net, x, target, square_length=7)[source]¶ An occlusion test that checks an image for its critical parts. In this function, a square part of the image is occluded (i.e. set to 0) and then the net is tested for its propensity to predict the correct label. One should expect that this propensity shrinks of critical parts of the image are occluded. If not, this indicates overfitting. Depending on the depth of the net and the size of the image, this function may take awhile to finish, since one prediction for each pixel of the image is made. Currently, all color channels are occluded at the same time. Also, this does not really work if images are randomly distorted by the batch iterator. See paper: Zeiler, Fergus 2013 :param net: The neural net to test. :type net: NeuralNet instance :param x: The input data, should be of shape (1, c, x, y). Only makes
sense with image data.
- Parameters
target (int) – The true value of the image. If the net makes several predictions, say 10 classes, this indicates which one to look at.
square_length (int (default=7)) – The length of the side of the square that occludes the image. Must be an odd number.
Results –
------- –
heat_array (np.array (with same size as image)) – An 2D np.array that at each point (i, j) contains the predicted probability of the correct class if the image is occluded by a square with center (i, j).
-
wbia_cnn.draw_net.
output_confusion_matrix
(X_test, results_path, test_results, model, **kwargs)[source]¶ currently hacky implementation, fix it later
-
wbia_cnn.draw_net.
plot_occlusion
(net, Xb, target, square_length=7, figsize=9, None)[source]¶ Plot which parts of an image are particularly import for the net to classify the image correctly. See paper: Zeiler, Fergus 2013 :param net: The neural net to test. :type net: NeuralNet instance :param Xb: The input data, should be of shape (b, c, 0, 1). Only makes
sense with image data.
- Parameters
target (list or numpy.array of ints) – The true values of the image. If the net makes several predictions, say 10 classes, this indicates which one to look at. If more than one sample is passed to Xb, each of them needs its own target.
square_length (int (default=7)) – The length of the side of the square that occludes the image. Must be an odd number.
figsize (tuple (int, int)) – Size of the figure.
Plots –
----- –
with 3 subplots (Figure) –
both images super-imposed. (and) –
-
wbia_cnn.draw_net.
pydot_to_image
(pydot_graph)[source]¶ References
http://stackoverflow.com/questions/4596962/display-graph-without-saving-using-pydot
-
wbia_cnn.draw_net.
save_confusion_matrix
(results_path, correct_y, predict_y, category_list, mapping_fn=None, data_x=None)[source]¶
-
wbia_cnn.draw_net.
show_arch_nx_graph
(layers, fnum=None, fullinfo=True)[source]¶ - CommandLine:
python -m wbia_cnn.draw_net show_arch_nx_graph:0 –show python -m wbia_cnn.draw_net show_arch_nx_graph:1 –show
- Example0:
>>> # ENABLE_DOCTEST >>> from wbia_cnn.draw_net import * # NOQA >>> from wbia_cnn import models >>> model = models.mnist.MNISTModel(batch_size=128, output_dims=10, >>> data_shape=(24, 24, 3)) >>> model.init_arch() >>> layers = model.get_all_layers() >>> show_arch_nx_graph(layers) >>> ut.quit_if_noshow() >>> import plottool as pt >>> ut.show_if_requested()
- Example1:
>>> # ENABLE_DOCTEST >>> from wbia_cnn.draw_net import * # NOQA >>> from wbia_cnn import models >>> model = models.SiameseCenterSurroundModel(autoinit=True) >>> layers = model.get_all_layers() >>> show_arch_nx_graph(layers) >>> ut.quit_if_noshow() >>> import plottool as pt >>> ut.show_if_requested()
-
wbia_cnn.draw_net.
show_confusion_matrix
(correct_y, predict_y, category_list, results_path, mapping_fn=None, data_x=None)[source]¶ Given the correct and predict labels, show the confusion matrix
- Parameters
correct_y (list of int) – the list of correct labels
predict_y (list of int) – the list of predict assigned labels
category_list (list of str) – the category list of all categories
- Displays:
matplotlib: graph of the confusion matrix
- Returns
None
TODO FIXME and simplify
-
wbia_cnn.draw_net.
show_convolutional_weights
(all_weights, use_color=None, limit=144, fnum=None, pnum=1, 1, 1)[source]¶ - Parameters
all_weights –
use_color (bool) –
limit (int) –
- CommandLine:
python -m wbia_cnn.draw_net –test-show_convolutional_weights –show python -m wbia_cnn.draw_net –test-show_convolutional_weights –show –index=1
# Need to fit mnist first python -m wbia_cnn _ModelFitting.fit:1 –vd
Example
>>> # DISABLE_DOCTEST >>> # Assumes mnist is trained >>> from wbia_cnn.draw_net import * # NOQA >>> from wbia_cnn import ingest_data >>> from wbia_cnn.models import MNISTModel >>> dataset = ingest_data.grab_mnist_category_dataset() >>> model = MNISTModel(batch_size=128, data_shape=dataset.data_shape, >>> name='bnorm', >>> output_dims=len(dataset.unique_labels), >>> batch_norm=True, >>> dataset_dpath=dataset.dataset_dpath) >>> model.encoder = None >>> model.init_arch() >>> model.load_model_state() >>> nn_layers = model.get_all_layers() >>> weighted_layers = [layer for layer in nn_layers if hasattr(layer, 'W')] >>> all_weights = weighted_layers[0].W.get_value() >>> print('all_weights.shape = %r' % (all_weights.shape,)) >>> use_color = None >>> limit = 64 >>> fig = show_convolutional_weights(all_weights, use_color, limit) >>> ut.quit_if_noshow() >>> import plottool as pt >>> pt.qt4ensure() >>> fig = show_convolutional_weights(all_weights, use_color, limit) >>> ut.show_if_requested()
Example
>>> # ENABLE_DOCTEST >>> from wbia_cnn.draw_net import * # NOQA >>> from wbia_cnn import models >>> from Lasagne.lasagne import layers >>> model = models.SiameseCenterSurroundModel(autoinit=True) >>> output_layer = model.get_output_layer() >>> nn_layers = layers.get_all_layers(output_layer) >>> weighted_layers = [layer for layer in nn_layers if hasattr(layer, 'W')] >>> index = ut.get_argval('--index', type_=int, default=0) >>> all_weights = weighted_layers[index].W.get_value() >>> print('all_weights.shape = %r' % (all_weights.shape,)) >>> use_color = None >>> limit = 64 >>> fig = show_convolutional_weights(all_weights, use_color, limit) >>> ut.show_if_requested()
-
wbia_cnn.draw_net.
show_saliency_heatmap
(model, dataset)[source]¶ https://github.com/dnouri/nolearn/blob/master/nolearn/lasagne/visualize.py
Example
>>> # DISABLE_DOCTEST >>> # Assumes mnist is trained >>> from wbia_cnn.draw_net import * # NOQA >>> from wbia_cnn import ingest_data >>> from wbia_cnn.models import MNISTModel >>> dataset = ingest_data.grab_mnist_category_dataset() >>> model = MNISTModel(batch_size=128, data_shape=dataset.data_shape, >>> name='bnorm', >>> output_dims=len(dataset.unique_labels), >>> batch_norm=True, >>> dataset_dpath=dataset.dataset_dpath) >>> model.encoder = None >>> model.init_arch() >>> model.load_model_state() >>> import plottool as pt >>> pt.qt4ensure() >>> show_saliency_heatmap(model, dataset) >>> ut.show_if_requested()
wbia_cnn.draw_results module¶
-
wbia_cnn.draw_results.
get_patch_chunk
(data_lists, label_list, flat_metadata, indicies=None, border_color=0, 0, 0, draw_meta=True, vert=True, fontScale=2.5)[source]¶ indicies = chunked_indicies[0]
- Parameters
data_lists (list) – list of lists. The first dimension is the data_per_label dim.
warped_patch1_list (list) –
warped_patch2_list (list) –
label_list (list) –
flat_metadata –
indicies –
- CommandLine:
python -m wbia_cnn.draw_results –test-get_patch_chunk –show python -m wbia_cnn.draw_results –test-get_patch_chunk
Example
>>> # ENABLE_DOCTEST >>> from wbia_cnn.draw_results import * # NOQA >>> from wbia_cnn import ingest_data >>> data, label_list = ingest_data.testdata_patchmatch2() >>> flat_metadata = {'fs': np.arange(len(label_list))} >>> data_lists = list(zip(*ut.ichunks(data, 2))) >>> indicies = np.arange(0, 10) >>> img, offset_list, sf_list, stacked_orig_sizes = get_patch_chunk(data_lists, label_list, flat_metadata, indicies) >>> result = str(img.shape) >>> print(result) >>> ut.quit_if_noshow() >>> import plottool as pt >>> pt.imshow(img) >>> ut.show_if_requested() (1920, 384, 3)
-
wbia_cnn.draw_results.
get_patch_multichunks
(data_lists, label_list, flat_metadata, multiindicies)[source]¶ - CommandLine:
python -m wbia_cnn.draw_results –test-get_patch_multichunks –show
Example
>>> # ENABLE_DOCTEST >>> from wbia_cnn.draw_results import * # NOQA >>> from wbia_cnn import ingest_data >>> data, label_list = ingest_data.testdata_patchmatch2() >>> flat_metadata = {} >>> warped_patch1_list, warped_patch2_list = list(zip(*ut.ichunks(data, 2))) >>> data_lists = (warped_patch1_list, warped_patch2_list, ) >>> multiindicies = [np.arange(0, 10), np.arange(10, 20), np.arange(20, 30) ] >>> stacked_img, stacked_offsets, stacked_sfs = get_patch_multichunks(data_lists, label_list, flat_metadata, multiindicies) >>> ut.quit_if_noshow() >>> import plottool as pt >>> pt.imshow(stacked_img) >>> ut.show_if_requested()
-
wbia_cnn.draw_results.
get_patch_sample_img
(warped_patch1_list, warped_patch2_list, label_list, flat_metadata, index_list, chunck_sizes=6, 10)[source]¶
-
wbia_cnn.draw_results.
interact_dataset
(labels, data, flat_metadata, data_per_label, **kwargs)[source]¶ - Parameters
labels –
data –
flat_metadata –
- CommandLine:
python -m wbia_cnn.draw_results –test-interact_dataset –show
Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn.draw_results import * # NOQA >>> from wbia_cnn import ingest_data >>> data, labels = ingest_data.testdata_patchmatch2() >>> flat_metadata = {'fs': np.arange(len(labels))} >>> result = interact_siamsese_data_patches(labels, data, flat_metadata) >>> ut.show_if_requested()
-
wbia_cnn.draw_results.
interact_patches
(label_list, data_lists, flat_metadata, sortby=None, figtitle=None, chunck_sizes=None, ibs=None, hack_one_per_aid=True, qreq_=None)[source]¶ - Parameters
label_list (list) –
data_lists (tuple of lists) – fixme bad name
flat_metadata –
sortby (None) – (default = None)
figtitle (None) – (default = None)
chunck_sizes (None) – (default = None)
- CommandLine:
python -m wbia_cnn.draw_results –exec-interact_patches –show
- SeeAlso:
python -m wbia_cnn.ingest_wbia –exec-extract_annotpair_training_chips –show
Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn.draw_results import * # NOQA >>> from wbia_cnn import ingest_data >>> data, labels = ingest_data.testdata_patchmatch2() >>> flat_metadata = {'fs': np.arange(len(labels))} >>> result = interact_siamsese_data_patches(labels, data, flat_metadata) >>> ut.show_if_requested() >>> print(result)
-
wbia_cnn.draw_results.
interact_siamsese_data_patches
(labels, data, flat_metadata, **kwargs)[source]¶ - Parameters
labels –
data –
flat_metadata –
- CommandLine:
python -m wbia_cnn.draw_results –test-interact_siamsese_data_patches –show
Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn.draw_results import * # NOQA >>> from wbia_cnn import ingest_data >>> data, labels = ingest_data.testdata_patchmatch2() >>> flat_metadata = {'fs': np.arange(len(labels))} >>> result = interact_siamsese_data_patches(labels, data, flat_metadata) >>> ut.show_if_requested()
wbia_cnn.experiments module¶
-
wbia_cnn.experiments.
sift_dataset_separability
(dataset)[source]¶ VERY HACKED RIGHT NOW. ONLY LIBERTY. BLINDLY CACHES
- Parameters
dataset –
- CommandLine:
python -m wbia_cnn.experiments –exec-sift_dataset_separability –show
Example
>>> # SCRIPT >>> from wbia_cnn.experiments import * # NOQA >>> from wbia_cnn import ingest_data >>> dataset = ingest_data.grab_liberty_siam_dataset(250000) >>> ut.quit_if_noshow() >>> sift_dataset_separability(dataset) >>> ut.show_if_requested()
-
wbia_cnn.experiments.
test_siamese_performance
(model, data, labels, flat_metadata, dataname='')[source]¶ - CommandLine:
utprof.py -m wbia_cnn –tf pz_patchmatch –db liberty –test –weights=liberty:current –arch=siaml2_128 –test python -m wbia_cnn –tf netrun –db liberty –arch=siaml2_128 –test –ensure python -m wbia_cnn –tf netrun –db liberty –arch=siaml2_128 –test –ensure –weights=new python -m wbia_cnn –tf netrun –db liberty –arch=siaml2_128 –train –weights=new python -m wbia_cnn –tf netrun –db pzmtest –weights=liberty:current –arch=siaml2_128 –test # NOQA python -m wbia_cnn –tf netrun –db pzmtest –weights=liberty:current –arch=siaml2_128
wbia_cnn.harness module¶
- DEPRICATED:
code is now in abstract_model under fitting
constructs the Theano optimization and trains a learning model, optionally by initializing the network with pre-trained weights.
http://cs231n.github.io/neural-networks-3/#distr
- Pretrained Models:
wbia_cnn.ingest_data module¶
-
wbia_cnn.ingest_data.
get_numpy_dataset2
(name, data_fpath, labels_fpath, training_dpath, cache=True)[source]¶
-
wbia_cnn.ingest_data.
get_wbia_part_siam_dataset
(**kwargs)[source]¶ PARTS based network data
- CommandLine:
python -m wbia_cnn.ingest_data –test-get_wbia_part_siam_dataset –show python -m wbia_cnn.ingest_data –test-get_wbia_part_siam_dataset –show –db PZ_Master1 –acfg_name timectrl python -m wbia_cnn.ingest_data –test-get_wbia_part_siam_dataset –show –db PZ_MTEST –acfg_name unctrl –dryrun
Example
>>> # ENABLE_DOCTEST >>> from wbia_cnn.ingest_data import * # NOQA >>> from wbia_cnn import draw_results >>> import wbia >>> kwargs = {} # ut.argparse_dict({'max_examples': None, 'num_top': 3}) >>> dataset = get_wbia_part_siam_dataset(**kwargs) >>> ut.quit_if_noshow() >>> dataset.interact(ibs=dataset.getprop('ibs')) >>> ut.show_if_requested()
-
wbia_cnn.ingest_data.
get_wbia_patch_siam_dataset
(**kwargs)[source]¶ - CommandLine:
python -m wbia_cnn.ingest_data –test-get_wbia_patch_siam_dataset –show python -m wbia_cnn.ingest_data –test-get_wbia_patch_siam_dataset –show –db PZ_Master1 –acfg_name default python -m wbia_cnn.ingest_data –test-get_wbia_patch_siam_dataset –show –db PZ_Master1 –acfg_name timectrl python -m wbia_cnn.ingest_data –test-get_wbia_patch_siam_dataset –show –db PZ_MTEST –acfg_name unctrl –dryrun
Example
>>> # ENABLE_DOCTEST >>> from wbia_cnn.ingest_data import * # NOQA >>> from wbia_cnn import draw_results >>> import wbia >>> kwargs = {} # ut.argparse_dict({'max_examples': None, 'num_top': 3}) >>> dataset = get_wbia_patch_siam_dataset(**kwargs) >>> ut.quit_if_noshow() >>> dataset.interact() >>> ut.show_if_requested()
-
wbia_cnn.ingest_data.
grab_liberty_siam_dataset
(pairs=250000)[source]¶ References
http://www.cs.ubc.ca/~mbrown/patchdata/patchdata.html https://github.com/osdf/datasets/blob/master/patchdata/dataset.py
Notes
“info.txt” contains the match information Each row of info.txt corresponds corresponds to a separate patch, with the patches ordered from left to right and top to bottom in each bitmap image.
3 types of metadata files
- info.txt - contains patch ids that correspond with the order of patches
in the bmp images In the format:
pointid, unused
- interest.txt -
interest points corresponding to patches with patchids has same number of rows as info.txt In the format:
reference image id, x, y, orientation, scale (in log2 units)
- m50_<d>_<d>_0.txt -
matches files patchID1 3DpointID1 unused1 patchID2 3DpointID2 unused2
- CommandLine:
python -m wbia_cnn.ingest_data –test-grab_liberty_siam_dataset –show
Example
>>> # ENABLE_DOCTEST >>> from wbia_cnn.ingest_data import * # NOQA >>> pairs = 500 >>> dataset = grab_liberty_siam_dataset(pairs) >>> ut.quit_if_noshow() >>> from wbia_cnn import draw_results >>> #ibsplugin.rrr() >>> flat_metadata = {} >>> data, labels = dataset.subset('full') >>> ut.quit_if_noshow() >>> warped_patch1_list = data[::2] >>> warped_patch2_list = data[1::2] >>> dataset.interact() >>> ut.show_if_requested()
-
wbia_cnn.ingest_data.
grab_mnist_category_dataset
()[source]¶ - CommandLine:
python -m wbia_cnn grab_mnist_category_dataset python -m wbia_cnn grab_mnist_category_dataset_float python -m wbia_cnn grab_mnist_category_dataset –show
Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn.ingest_data import * # NOQA >>> dataset = grab_mnist_category_dataset() >>> dataset.print_subset_info() >>> dataset.print_dir_tree() >>> ut.quit_if_noshow() >>> inter = dataset.interact() >>> ut.show_if_requested()
-
wbia_cnn.ingest_data.
grab_mnist_category_dataset_float
()[source]¶ - CommandLine:
python -m wbia_cnn grab_mnist_category_dataset_float python -m wbia_cnn grab_mnist_category_dataset_float –show
Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn.ingest_data import * # NOQA >>> dataset = grab_mnist_category_dataset_float() >>> dataset.print_subset_info() >>> dataset.print_dir_tree() >>> ut.quit_if_noshow() >>> inter = dataset.interact() >>> ut.show_if_requested()
-
wbia_cnn.ingest_data.
grab_mnist_siam_dataset
()[source]¶ - CommandLine:
python -m wbia_cnn.ingest_data –test-grab_mnist_siam_dataset –show
Example
>>> # ENABLE_DOCTEST >>> from wbia_cnn.ingest_data import * # NOQA >>> dataset = grab_mnist_siam_dataset() >>> ut.quit_if_noshow() >>> from wbia_cnn import draw_results >>> #ibsplugin.rrr() >>> flat_metadata = {} >>> data, labels = dataset.subset('full') >>> ut.quit_if_noshow() >>> dataset.interact() >>> ut.show_if_requested()
-
wbia_cnn.ingest_data.
grab_siam_dataset
(ds_tag=None)[source]¶ Will build the dataset using the command line if it doesn’t exist
- CommandLine:
python -m wbia_cnn.ingest_data –test-grab_siam_dataset –db mnist –show python -m wbia_cnn.ingest_data –test-grab_siam_dataset –db liberty –show python -m wbia_cnn.ingest_data –test-grab_siam_dataset –db PZ_MTEST –show
python -m wbia_cnn.ingest_data –test-grab_siam_dataset –db PZ_MTEST –show –nohud –nometa python -m wbia_cnn.ingest_data –test-grab_siam_dataset –db liberty –show –nohud –nometa
Example
>>> # ENABLE_DOCTEST >>> from wbia_cnn.ingest_data import * # NOQA >>> ds_tag = None >>> dataset = grab_siam_dataset(ds_tag=ds_tag) >>> ut.quit_if_noshow() >>> from wbia_cnn import draw_results >>> dataset.interact(ibs=dataset.getprop('ibs', None), key='test', chunck_sizes=(8, 4)) >>> ut.show_if_requested()
wbia_cnn.ingest_helpers module¶
-
wbia_cnn.ingest_helpers.
extract_liberty_style_patches
(ds_path, pairs)[source]¶ - CommandLine:
python -m wbia_cnn.ingest_data –test-grab_cached_liberty_data –show
wbia_cnn.ingest_wbia module¶
-
class
wbia_cnn.ingest_wbia.
PartMatchDataConfig
(**kwargs)[source]¶ Bases:
wbia.dtool.base.Config
-
_param_info_list
= [<ParamInfo(part_chip_width=256)>, <ParamInfo(part_chip_height=128)>, <ParamInfo(colorspace=gray)>]¶
-
-
class
wbia_cnn.ingest_wbia.
PatchMetricDataConfig
(**kwargs)[source]¶ Bases:
wbia.dtool.base.Config
-
_param_info_list
= [<ParamInfo(patch_size=64)>, <ParamInfo(colorspace=gray)>]¶
-
-
wbia_cnn.ingest_wbia.
cached_part_match_training_data_fpaths
(ibs, aid_pairs, label_list, flat_metadata, **kwargs)[source]¶ - CommandLine:
- python -m wbia_cnn –tf netrun –db PZ_MTEST
–acfg ctrl:pername=None,excluderef=False –ensuredata –show –datatype=siam-part –nocache-train –nocache-cnn
-
wbia_cnn.ingest_wbia.
cached_patchmetric_training_data_fpaths
(ibs, aid1_list, aid2_list, kpts1_m_list, kpts2_m_list, fm_list, metadata_lists, **kwargs)[source]¶ todo use size in cfgstrings kwargs is used for PatchMetricDataConfig
from wbia_cnn.ingest_wbia import *
-
wbia_cnn.ingest_wbia.
extract_annotpair_training_chips
(ibs, aid_pairs, **kwargs)[source]¶ - CommandLine:
python -m wbia_cnn.ingest_wbia extract_annotpair_training_chips –show
Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn.ingest_wbia import * # NOQA >>> import wbia >>> # build test data >>> if False: >>> ibs = wbia.opendb(defaultdb='PZ_Master1') >>> acfg_name = ut.get_argval(('--aidcfg', '--acfg', '-a'), >>> type_=str, >>> default='ctrl:pername=None,excluderef=False,contributor_contains=FlankHack') >>> else: >>> ibs = wbia.opendb(defaultdb='PZ_MTEST') >>> acfg_name = ut.get_argval(('--aidcfg', '--acfg', '-a'), >>> type_=str, >>> default='ctrl:pername=None,excluderef=False,index=0:20:2') >>> #ibs = wbia.opendb(defaultdb='PZ_FlankHack') >>> aid_pairs, label_list, flat_metadata = get_aidpairs_partmatch(ibs, acfg_name) >>> s = slice(2, len(aid_pairs), len(aid_pairs) // ut.get_argval('--x', type_=int, default=8)) >>> #aid_pairs = aid_pairs[s] >>> #label_list = label_list[s] >>> #flat_metadata = dict([(key, val[s]) for key, val in flat_metadata.items()]) >>> rchip1_list, rchip2_list = extract_annotpair_training_chips(ibs, aid_pairs) >>> ut.quit_if_noshow() >>> from wbia_cnn import draw_results # NOQA >>> interact = draw_results.interact_patches(label_list, (rchip1_list, rchip2_list), flat_metadata, chunck_sizes=(2, 2), ibs=ibs) >>> ut.show_if_requested()
-
wbia_cnn.ingest_wbia.
extract_orientation_chips
(ibs, gid_list, image_size=128, training=True, verbose=True)[source]¶
-
wbia_cnn.ingest_wbia.
flatten_patch_data
(ibs, aid1_list, aid2_list, kpts1_m_list, kpts2_m_list, fm_list, metadata_lists)[source]¶
-
wbia_cnn.ingest_wbia.
get_aidpair_patchmatch_training_data
(ibs, aid1_list, aid2_list, kpts1_m_list, kpts2_m_list, fm_list, metadata_lists, patch_size, colorspace)[source]¶ FIXME: errors on get_aidpairs_and_matches(ibs, 1)
- CommandLine:
python -m wbia_cnn.ingest_wbia –test-get_aidpair_patchmatch_training_data –show
Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn.ingest_wbia import * # NOQA >>> import wbia >>> # build test data >>> ibs = wbia.opendb(defaultdb='PZ_MTEST') >>> tup = get_aidpairs_and_matches(ibs, 6) >>> (aid1_list, aid2_list, kpts1_m_list, kpts2_m_list, fm_list, metadata_lists) = tup >>> pmcfg = PatchMetricDataConfig() >>> patch_size = pmcfg['patch_size'] >>> colorspace = pmcfg['colorspace'] >>> # execute function >>> tup = get_aidpair_patchmatch_training_data(ibs, aid1_list, ... aid2_list, kpts1_m_list, kpts2_m_list, fm_list, metadata_lists, ... patch_size, colorspace) >>> aid1_list_, aid2_list_, warped_patch1_list, warped_patch2_list, flat_metadata = tup >>> ut.quit_if_noshow() >>> label_list = get_aidpair_training_labels(ibs, aid1_list_, aid2_list_) >>> draw_results.interact_patches(label_list, (warped_patch1_list, warped_patch2_list), flat_metadata) >>> ut.show_if_requested()
-
wbia_cnn.ingest_wbia.
get_aidpair_training_labels
(ibs, aid1_list_, aid2_list_)[source]¶ - Returns
true in positions of matching, and false in positions of not matching
- Return type
ndarray
Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn.ingest_wbia import * # NOQA >>> import wbia >>> # build test data >>> ibs = wbia.opendb(defaultdb='PZ_MTEST') >>> tup = get_aidpairs_and_matches(ibs) >>> (aid1_list, aid2_list) = tup[0:2] >>> aid1_list = aid1_list[0:min(100, len(aid1_list))] >>> aid2_list = aid2_list[0:min(100, len(aid2_list))] >>> # execute function >>> labels = get_aidpair_training_labels(ibs, aid1_list, aid2_list) >>> result = ('labels = %s' % (ut.numpy_str(labels, threshold=10),)) >>> print(result) labels = np.array([1, 0, 0, ..., 0, 1, 0], dtype=np.int32)
-
wbia_cnn.ingest_wbia.
get_aidpairs_and_matches
(ibs, max_examples=None, num_top=3, controlled=True, min_featweight=None, acfg_name=None)[source]¶ Gets data for training a patch match network.
- Parameters
ibs (IBEISController) – ibeis controller object
max_examples (None) – (default = None)
num_top (int) – (default = 3)
controlled (bool) – (default = True)
- Returns
- patchmatch_tup = (aid1_list, aid2_list, kpts1_m_list,
kpts2_m_list, fm_list, metadata_lists)
aid pairs and matching keypoint pairs as well as the original index of the feature matches
- Return type
tuple
- CommandLine:
python -m wbia_cnn.ingest_wbia get_aidpairs_and_matches –show python -m wbia_cnn.ingest_wbia –test-get_aidpairs_and_matches –db PZ_Master0 python -m wbia_cnn.ingest_wbia –test-get_aidpairs_and_matches –db PZ_Master1 –acfg default –show python -m wbia_cnn.ingest_wbia –test-get_aidpairs_and_matches –db PZ_MTEST –acfg ctrl:qindex=0:10 –show python -m wbia_cnn.ingest_wbia –test-get_aidpairs_and_matches –db NNP_Master3
- python -m wbia_cnn.ingest_wbia –test-get_aidpairs_and_matches –db PZ_MTEST
–acfg default:is_known=True,qmin_pername=2,view=primary,species=primary,minqual=ok –show
- python -m wbia_cnn.ingest_wbia –test-get_aidpairs_and_matches –db PZ_Master1
–acfg default:is_known=True,qmin_pername=2,view=primary,species=primary,minqual=ok –show
Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn.ingest_wbia import * # NOQA >>> import wbia >>> # build test data >>> ibs = wbia.opendb(defaultdb='PZ_MTEST') >>> acfg_name = ut.get_argval(('--aidcfg', '--acfg', '-a', '--acfg-name'), ... type_=str, ... default='ctrl:qindex=0:10') >>> max_examples = None >>> num_top = None >>> controlled = True >>> min_featweight = .99 >>> patchmatch_tup = get_aidpairs_and_matches( >>> ibs, max_examples=max_examples, num_top=num_top, >>> controlled=controlled, min_featweight=min_featweight, >>> acfg_name=acfg_name) >>> (aid1_list, aid2_list, kpts1_m_list, kpts2_m_list, fm_list, metadata_lists) = patchmatch_tup >>> ut.quit_if_noshow() >>> print('Visualizing') >>> # Visualize feature scores >>> tup = flatten_patch_data( >>> ibs, aid1_list, aid2_list, kpts1_m_list, kpts2_m_list, fm_list, >>> metadata_lists) >>> labels, flat_metadata = tup[2:] >>> fs = flat_metadata['fs'] >>> encoder = vt.ScoreNormalizer(adjust=1) >>> encoder.fit(fs, labels) >>> encoder.visualize(bin_width=.001, fnum=None) >>> # Visualize parent matches >>> _iter = list(zip(aid1_list, aid2_list, kpts1_m_list, kpts2_m_list, fm_list)) >>> _iter = ut.InteractiveIter(_iter, display_item=False) >>> import plottool as pt >>> import wbia.viz >>> for aid1, aid2, kpts1, kpts2, fm in _iter: >>> pt.reset() >>> print('aid2 = %r' % (aid2,)) >>> print('aid1 = %r' % (aid1,)) >>> print('len(fm) = %r' % (len(fm),)) >>> wbia.viz.viz_matches.show_matches2(ibs, aid1, aid2, fm=None, kpts1=kpts1, kpts2=kpts2) >>> pt.update() >>> ut.show_if_requested()
-
wbia_cnn.ingest_wbia.
get_aidpairs_partmatch
(ibs, acfg_name)[source]¶ - CommandLine:
python -m wbia_cnn.ingest_wbia –exec-get_aidpairs_partmatch
- SeeAlso:
extract_annotpair_training_chips
Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn.ingest_wbia import * # NOQA >>> import wbia >>> # build test data >>> ibs = wbia.opendb(defaultdb='PZ_Master1') >>> #ibs = wbia.opendb(defaultdb='PZ_MTEST') >>> #ibs = wbia.opendb(defaultdb='PZ_FlankHack') >>> acfg_name = ut.get_argval(('--aidcfg', '--acfg', '-a'), ... type_=str, ... default='ctrl:pername=None,excluderef=False,contributor_contains=FlankHack') >>> aid_pairs, label_list, flat_metadata = get_aidpairs_partmatch(ibs, acfg_name)
-
wbia_cnn.ingest_wbia.
get_aoi2_training_data
(ibs, image_size=192, dest_path=None, target_species_list=None, train_gid_list=None, purge=True, cache=True)[source]¶ Get data for bg
-
wbia_cnn.ingest_wbia.
get_aoi_training_data
(ibs, dest_path=None, target_species_list=None, purge=True)[source]¶ Get data for bg
-
wbia_cnn.ingest_wbia.
get_background_training_patches2
(ibs, target_species, dest_path=None, patch_size=48, patch_size_min=0.8, patch_size_max=1.25, annot_size=300, patience=20, patches_per_annotation=30, global_limit=None, train_gid_set=None, visualize=False, visualize_path=None, tiles=False, inside_boundary=True, purge=False, shuffle=True, supercharge_negative_multiplier=2.0, undercharge_negative_multiplier=0.5)[source]¶ Get data for bg
-
wbia_cnn.ingest_wbia.
get_cnn_classifier2_training_images
(ibs, category_set=None, category_mapping={}, dest_path=None, train_gid_set=None, image_size=192, purge=True, cache=True, skip_rate=0.0)[source]¶
-
wbia_cnn.ingest_wbia.
get_cnn_classifier_binary_training_images
(ibs, category_list, dest_path=None, image_size=192, purge=True, skip_rate=0.0, skip_rate_pos=0.0, skip_rate_neg=0.0)[source]¶
-
wbia_cnn.ingest_wbia.
get_cnn_classifier_cameratrap_binary_training_images
(ibs, positive_imageset_id, negative_imageset_id, dest_path=None, image_size=192, purge=True, skip_rate=0.0, skip_rate_pos=0.0, skip_rate_neg=0.0)[source]¶
-
wbia_cnn.ingest_wbia.
get_cnn_labeler_training_images
(ibs, dest_path=None, image_size=128, category_list=None, min_examples=10, category_mapping=None, viewpoint_mapping=None, purge=True, strict=True, skip_rate=0.0)[source]¶
-
wbia_cnn.ingest_wbia.
get_cnn_qualifier_training_images
(ibs, dest_path=None, image_size=128, purge=True)[source]¶
-
wbia_cnn.ingest_wbia.
get_orientation_training_images
(ibs, dest_path=None, **kwargs)[source]¶ Gets data for training a patch match network.
- Parameters
ibs (IBEISController) – ibeis controller object
max_examples (None) – (default = None)
num_top (int) – (default = 3)
controlled (bool) – (default = True)
- Returns
- patchmatch_tup = (aid1_list, aid2_list, kpts1_m_list,
kpts2_m_list, fm_list, metadata_lists)
aid pairs and matching keypoint pairs as well as the original index of the feature matches
- Return type
tuple
- CommandLine:
python -m wbia_cnn.ingest_wbia –test-get_orientation_training_images –dbdir /Datasets/BACKGROUND/PZ_Master1
Example
>>> # ENABLE_DOCTEST >>> from wbia_cnn.ingest_wbia import * # NOQA >>> import wbia >>> # build test data >>> ibs = wbia.opendb(defaultdb='PZ_MTEST') >>> get_orientation_training_images(ibs)
-
wbia_cnn.ingest_wbia.
get_patchmetric_training_data_and_labels
(ibs, aid1_list, aid2_list, kpts1_m_list, kpts2_m_list, fm_list, metadata_lists, patch_size, colorspace)[source]¶ Notes
# FIXME: THERE ARE INCORRECT CORRESPONDENCES LABELED AS CORRECT THAT # NEED MANUAL CORRECTION EITHER THROUGH EXPLICIT LABLEING OR # SEGMENTATION MASKS
- CommandLine:
python -m wbia_cnn.ingest_wbia –test-get_patchmetric_training_data_and_labels –show
Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn.ingest_wbia import * # NOQA >>> import wbia >>> # build test data >>> ibs = wbia.opendb(defaultdb='PZ_MTEST') >>> (aid1_list, aid2_list, kpts1_m_list, kpts2_m_list, fm_list, metadata_lists) = get_aidpairs_and_matches(ibs, 10, 3) >>> pmcfg = PatchMetricDataConfig() >>> patch_size = pmcfg['patch_size'] >>> colorspace = pmcfg['colorspace'] >>> data, labels, flat_metadata = get_patchmetric_training_data_and_labels(ibs, ... aid1_list, aid2_list, kpts1_m_list, kpts2_m_list, fm_list, ... metadata_lists, patch_size, colorspace) >>> ut.quit_if_noshow() >>> draw_results.interact_siamsese_data_patches(labels, data) >>> ut.show_if_requested()
wbia_cnn.lasagne_ext module¶
-
wbia_cnn.lasagne_ext.
l1
(layer, include_biases=False)[source]¶ custom should move to regulariztion.lasagne.l1
NOT WORKING
-
wbia_cnn.lasagne_ext.
siamese_loss
(G, Y_padded, data_per_label=2, T=<module 'theano.tensor' from '/Users/jason.parham/virtualenv/wildme3.7/lib/python3.7/site-packages/Theano-1.0.5-py3.7.egg/theano/tensor/__init__.py'>)[source]¶ - Parameters
G – network output
Y_padded – : target groundtruth labels (padded at the end with dummy values)
References
https://www.cs.nyu.edu/~sumit/research/assets/cvpr05.pdf https://github.com/Lasagne/Lasagne/issues/168
- CommandLine:
python -m wbia_cnn.lasagne_ext –test-siamese_loss # Train Network python -m wbia_cnn.train –test-pz_patchmatch –vtd –max-examples=16 –batch_size=128 –learning_rate .0000001
- CommandLine:
python -m wbia_cnn.lasagne_ext –test-siamese_loss
Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn.lasagne_ext import * # NOQA >>> # numpy testing but in reality these are theano functions >>> verbose = True >>> G, Y_padded = testdata_contrastive_loss() >>> T = np >>> np.abs_ = np.abs >>> avg_loss = siamese_loss(G, Y_padded, T=T)
wbia_cnn.net_strs module¶
-
wbia_cnn.net_strs.
get_layer_info
(layer)[source]¶ - Parameters
layer –
- Returns
layer_info
- Return type
?
- CommandLine:
python -m wbia_cnn.net_strs get_layer_info –show
Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn.net_strs import * # NOQA >>> from wbia_cnn import models >>> model = models.mnist.MNISTModel(batch_size=8, data_shape=(24, 24, 1), output_dims=10) >>> model.init_arch() >>> nn_layers = model.get_all_layers() >>> for layer in nn_layers: >>> layer_info = get_layer_info(layer) >>> print(ut.repr3(layer_info, nl=1))
-
wbia_cnn.net_strs.
get_layer_info_str
(output_layer, batch_size=128)[source]¶ - Parameters
output_layer (lasagne.layers.Layer) –
- CommandLine:
python -m wbia_cnn.net_strs –test-get_layer_info_str:0 python -m wbia_cnn.net_strs –test-get_layer_info_str:1
Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn.net_strs import * # NOQA >>> from wbia_cnn import models >>> model = models.DummyModel(data_shape=(24, 24, 3), autoinit=True) >>> output_layer = model.output_layer >>> result = get_layer_info_str(output_layer) >>> result = '\n'.join([x.rstrip() for x in result.split('\n')]) >>> print(result) Network Structure: index Layer Outputs Bytes OutShape Params 0 Input 1,728 55,296 (8, 3, 24, 24) [] 1 Conv2D 7,744 249,600 (8, 16, 22, 22) [W(16,3,3,3, {t,r}), b(16, {t})] 2 Conv2D 7,056 229,952 (8, 16, 21, 21) [W(16,16,2,2, {t,r}), b(16, {t})] 3 Dense 8 226,080 (8, 8) [W(7056,8, {t,r}), b(8, {t})] 4 Dense 5 340 (8, 5) [W(8,5, {t,r}), b(5, {t})] ...this model has 57,989 learnable parameters ...this model will use 761,268 bytes = 743.43 KB
Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn.net_strs import * # NOQA >>> from wbia_cnn import models >>> model = models.mnist.MNISTModel(batch_size=128, output_dims=10, >>> data_shape=(24, 24, 3)) >>> model.init_arch() >>> output_layer = model.output_layer >>> result = get_layer_info_str(output_layer) >>> result = '\n'.join([x.rstrip() for x in result.split('\n')]) >>> print(result)
-
wbia_cnn.net_strs.
make_layer_json_dict
(layer, layer_info, layer_to_id, extra=True)[source]¶ >>> from wbia_cnn.net_strs import * # NOQA
-
wbia_cnn.net_strs.
make_layer_str
(layer, with_name=True)[source]¶ - Parameters
layer (lasagne.Layer) – a network layer
-
wbia_cnn.net_strs.
print_pretrained_weights
(pretrained_weights, lbl='')[source]¶ - Parameters
pretrained_weights (list of ndarrays) – represents layer weights
lbl (str) – label
wbia_cnn.netrun module¶
- FIXME:
sometimes you have to chown -R user:user ~/.theano or run with sudo the first time after roboot, otherwise you get errors
- CommandLineHelp:
python -m wbia_cnn –tf netrun <networkmodel>
- –dataset, –ds = <dstag>:<subtag>
dstag is the main dataset name (eg PZ_MTEST), subtag are parameters to modify (max_examples=3)
- –weights, -w = |new|<checkpoint_tag>|<dstag>:<checkpoint_tag> (default: <checkpoint_tag>)
new will initialize clean weights. a checkpoint tag will try to to match a saved model state in the history. can load weights from an external dataset. <checkpoint_tag> defaults to current
- –arch, -a = <archtag>
model architecture tag (eg siaml2_128, siam2stream, viewpoint)
- –device = <processor>
sets theano device flag to a processor like gpu0, gpu1, or cpu0
- CommandLine:
python -m wbia_cnn –tf merge_ds_tags –alias-list gz-gray girm pzmtest nnp
Example
>>> # ENABLE_DOCTEST >>> from wbia_cnn.train import * # NOQA >>> ds_alias_list = ut.get_argval('--alias-list', type_=list, default=[]) >>> result = merge_ds_tags(ds_alias_list) >>> print(result)
-
wbia_cnn.netrun.
netrun
()[source]¶ - CommandLine:
# — UTILITY python -m wbia_cnn –tf get_juction_dpath –show
# — DATASET BUILDING — # Build Dataset Aliases python -m wbia_cnn –tf netrun –db PZ_MTEST –acfg ctrl –ensuredata –show python -m wbia_cnn –tf netrun –db PZ_Master1 –acfg timectrl –ensuredata python -m wbia_cnn –tf netrun –db PZ_Master1 –acfg timectrl:pername=None –ensuredata python -m wbia_cnn –tf netrun –db PZ_Master1 –acfg timectrl:pername=None –ensuredata python -m wbia_cnn –tf netrun –db mnist –ensuredata –show python -m wbia_cnn –tf netrun –db mnist –ensuredata –show –datatype=category python -m wbia_cnn –tf netrun –db mnist –ensuredata –show –datatype=siam-patch
python -m wbia_cnn –tf netrun –db PZ_Master1 –acfg ctrl:pername=None,excluderef=False,contributor_contains=FlankHack –ensuredata –show –datatype=siam-part
# Parts based datasets python -m wbia_cnn –tf netrun –db PZ_MTEST –acfg ctrl –datatype=siam-part –ensuredata –show
% Patch based dataset (big one) python -m wbia_cnn –tf netrun –db PZ_Master1 –acfg default:is_known=True,qmin_pername=2,view=primary,species=primary,minqual=ok –ensuredata –show –vtd python -m wbia_cnn –tf netrun –ds pzm4 –weights=new –arch=siaml2_128 –train –monitor python -m wbia_cnn –tf netrun –ds pzm4 –arch=siaml2_128 –test python -m wbia_cnn –tf netrun –ds pzm4 –arch=siaml2_128 –veryverbose –no-flask
# — TRAINING — python -m wbia_cnn –tf netrun –db PZ_Master1 –acfg default:is_known=True,qmin_pername=2,view=primary,species=primary,minqual=ok –weights=new –arch=siaml2_128 –train –monitor
python -m wbia_cnn –tf netrun –ds timectrl_pzmaster1 –acfg ctrl:pername=None,excluderef=False,contributor_contains=FlankHack –train –weights=new –arch=siaml2_128 –monitor # NOQA python -m wbia_cnn –tf netrun –ds timectrl_pzmaster1 –acfg ctrl:pername=None,excluderef=False –train –weights=new –arch=siaml2_128 –monitor # NOQA python -m wbia_cnn –tf netrun –ds pzmtest –weights=new –arch=siaml2_128 –train –monitor –DEBUG_AUGMENTATION python -m wbia_cnn –tf netrun –ds pzmtest –weights=new –arch=siaml2_128 –train –monitor
python -m wbia_cnn –tf netrun –ds flankhack –weights=new –arch=siaml2_partmatch –train –monitor –learning_rate=.00001 python -m wbia_cnn –tf netrun –ds flankhack –weights=new –arch=siam_deepfaceish –train –monitor –learning_rate=.00001
# Different ways to train mnist python -m wbia_cnn –tf netrun –db mnist –weights=new –arch=mnist_siaml2 –train –monitor –datatype=siam-patch python -m wbia_cnn –tf netrun –db mnist –weights=new –arch=mnist-category –train –monitor –datatype=category
# — INITIALIZED-TRAINING — python -m wbia_cnn –tf netrun –ds pzmtest –arch=siaml2_128 –weights=gz-gray:current –train –monitor
# — TESTING — python -m wbia_cnn –tf netrun –db liberty –weights=liberty:current –arch=siaml2_128 –test python -m wbia_cnn –tf netrun –db PZ_Master0 –weights=combo:current –arch=siaml2_128 –testall
Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn.netrun import * # NOQA >>> netrun() >>> ut.show_if_requested()
wbia_cnn.process module¶
-
wbia_cnn.process.
numpy_processed_directory
(project_name, numpy_ids_file_name='ids.npy', numpy_x_file_name='X.npy', numpy_y_file_name='y.npy', labels_file_name='labels.csv', reset=True)[source]¶
-
wbia_cnn.process.
numpy_processed_directory2
(extracted_path, numpy_ids_file_name='ids.npy', numpy_x_file_name='X.npy', numpy_y_file_name='y.npy', labels_file_name='labels.csv', reset=True, verbose=False)[source]¶
-
wbia_cnn.process.
numpy_processed_directory3
(extracted_path, numpy_ids_file_name='ids.npy', numpy_x_file_name='X.npy', numpy_y_file_name='y.npy', labels_file_name='labels.csv', categories_file_name='categories.csv', reset=True, verbose=False)[source]¶
-
wbia_cnn.process.
numpy_processed_directory4
(extracted_path, numpy_ids_file_name='ids.npy', numpy_x_file_name='X.npy', numpy_y_file_name='y.npy', labels_file_name='labels.csv', reset=True, verbose=False)[source]¶
wbia_cnn.sandbox module¶
wbia_cnn.test module¶
tests a test set of data using a specified, pre0trained model and weights
wbia_cnn.theano_ext module¶
wbia_cnn.utils module¶
TODO: depricate this file eventually when geral model and dataset structure is fully setup
-
wbia_cnn.utils.
convert_cv2_images_to_theano_images
(img_list)[source]¶ Converts b01c to bc01
Converts a list of cv2-style images into a single numpy array of nonflat theano-style images.
h=height, w=width, b=batchid, c=channel
- Parameters
img_list (list of ndarrays) – a list of numpy arrays with shape [h, w, c]
- Returns
in the shape [b, (c x h x w)]
- Return type
data
- CommandLine:
python -m wbia_cnn.utils –test-convert_cv2_images_to_theano_images
Example
>>> # ENABLE_DOCTEST >>> from wbia_cnn.utils import * # NOQA >>> import vtool as vt >>> # build test data >>> # execute function >>> img_list, width, height, channels = testdata_imglist() >>> data = convert_cv2_images_to_theano_images(img_list) >>> data[0].reshape(3, 32, 32)[:, 0:2, 0:2] >>> subset = (data[0].reshape(3, 32, 32)[:, 0:2, 0:2]) >>> #result = str(np.transpose(subset, (1, 2, 0))) >>> result = str(subset).replace('\n', '') >>> print(result) [[[ 0 3] [ 96 99]] [[ 1 4] [ 97 100]] [[ 2 5] [ 98 101]]]
-
wbia_cnn.utils.
convert_theano_images_to_cv2_images
(data, *args)[source]¶ Converts bc01 to b01c
- Parameters
data (ndarray) – in the shape [b, (c x h x w)]
- Returns
a list of numpy arrays with shape [h, w, c]
- Return type
img_list (list of ndarrays)
- CommandLine:
python -m wbia_cnn.utils –test-convert_data_to_imglist
Example
>>> # ENABLE_DOCTEST >>> from wbia_cnn.utils import * # NOQA >>> # build test data >>> img_list, width, height, channels = testdata_imglist() >>> data = convert_cv2_images_to_theano_images(np.array(img_list)) >>> img_list2 = convert_theano_images_to_cv2_images(data) >>> assert np.all(img_list == img_list2)
-
wbia_cnn.utils.
data_label_shuffle
(X, y, data_per_label=1, seed=None)[source]¶ - CommandLine:
python -m wbia_cnn.utils –test-data_label_shuffle
Example
>>> # ENABLE_DOCTEST >>> from wbia_cnn.utils import * # NOQA >>> X, y, data_per_label = testdata_xy() >>> data_per_label = 2 >>> seed = 42 >>> result = data_label_shuffle(X, y, data_per_label, seed=seed) >>> print(result)
-
wbia_cnn.utils.
evaluate_symbolic_layer
(get_output_for, inputdata_, input_type=None, **kwargs)[source]¶ helper for testing lasagne layers
-
wbia_cnn.utils.
expand_data_indicies
(label_indices, data_per_label=1)[source]¶ when data_per_label > 1, gives the corresponding data indicies for the data indicies
-
wbia_cnn.utils.
extract_patches_stride
(image, patch_size, stride)[source]¶ Using the input image, take a strided sampling of patches from the image
The patches are extracted (cropped copies) using the patch_size and stride. If the patch size and stride do not evenly cover the source image in width or height, the fractional border is strided explicitly, meaning that the final row or column will fit precicely against the image border. As a result, the final row and column will most likely have more overlap with the penultimate row and column.
- Parameters
image (numpy.ndarray) – the image that the patches will be extracted from
patch_size (int, tuple of int) – the size of the patches to be extracted
stride (int, tuple of int) – the stride to be used when extracting the patches.
- Returns
the list of image patches extracted and a list of the coordinates from the original image space where each patch was extracted. The coordinates are in the form of a 4-tuple, (top left x, top left y, bottom right x, bottom right y).
- Return type
patch_list, coord_list (list of numpy.ndarray, list of tuple of int)
-
wbia_cnn.utils.
get_gpu_memory
()[source]¶ References
https://groups.google.com/forum/#!topic/theano-users/2EdclcmZazU https://gist.github.com/matpalm/9c0c7c6a6f3681a0d39d
- CommandLine:
python -m wbia_cnn.utils –test-get_gpu_memory
Example
>>> # ENABLE_DOCTEST >>> from wbia_cnn.utils import * # NOQA >>> result = get_gpu_memory() >>> print(result)
-
wbia_cnn.utils.
get_printcolinfo
(requested_headers_)[source]¶ Example
>>> # ENABLE_DOCTEST >>> from wbia_cnn.utils import * # NOQA >>> requested_headers_ = None >>> printcol_info = get_printcolinfo(requested_headers)
-
wbia_cnn.utils.
make_random_indicies
(num, seed=None)[source]¶ - Parameters
num (int) –
seed (hashable) –
- Returns
random_indicies
- Return type
ndarray
- CommandLine:
python -m wbia_cnn.utils –test-make_random_indicies
Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn.utils import * # NOQA >>> num = 10 >>> seed = 42 >>> random_indicies = make_random_indicies(num, seed) >>> result = str(random_indicies) >>> print(result) [8 1 5 0 7 2 9 4 3 6]
-
wbia_cnn.utils.
save_pretrained_weights_slice
(pretrained_weights, weights_path, slice_=slice(None, None, None))[source]¶ Used to save a slice of pretrained weights. The doctest will publish a new set of weights
- CommandLine:
python -m wbia_cnn.utils –test-save_pretrained_weights_slice –net=’vggnet_full’ –slice=’slice(0,6)’ python -m wbia_cnn.utils –test-save_pretrained_weights_slice –net=’vggnet_full’ –slice=’slice(0,30)’ python -m wbia_cnn.utils –test-save_pretrained_weights_slice –net=’caffenet_full’ –slice=’slice(0,6)’ python -m wbia_cnn.utils –test-save_pretrained_weights_slice –net=’caffenet_full’ –slice=’slice(0,?)’
Example
>>> # DISABLE_DOCTEST >>> # Build a new subset of an existing model >>> from wbia_cnn.models import * # NOQA >>> from wbia_cnn._plugin_grabmodels import ensure_model >>> # Get base model weights >>> modelname = ut.get_argval('--net', type_=str, default='vggnet_full') >>> weights_path = ensure_model(modelname) >>> pretrained_weights = ut.load_cPkl(weights_path) >>> # Get the slice you want >>> slice_str = ut.get_argval('--slice', type_=str, default='slice(0, 6)') >>> slice_ = eval(slice_str, globals(), locals()) >>> # execute function >>> sliced_weights_path = save_pretrained_weights_slice(pretrained_weights, weights_path, slice_) >>> # PUT YOUR PUBLISH PATH HERE >>> publish_fpath = ut.truepath('~/Dropbox/IBEIS') >>> ut.copy(sliced_weights_path, publish_fpath)
-
wbia_cnn.utils.
slice_data_labels
(X, y, batch_size, batch_index, data_per_label, wraparound=False, verbose=False)[source]¶ - CommandLine:
python -m wbia_cnn.utils –test-slice_data_labels
Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn.utils import * # NOQA >>> X = np.random.rand(67, 3, 5, 4) >>> y = (np.random.rand(67) * 4).astype(np.int32) >>> batch_size = 32 >>> batch_index = 2 >>> data_per_label = 1 >>> wraparound = True >>> verbose = False >>> Xb, yb = slice_data_labels(X, y, batch_size, batch_index, data_per_label, wraparound, verbose) >>> result = str(Xb.shape) >>> print(result) (32, 3, 5, 4)
-
wbia_cnn.utils.
testdata_imglist
(shape=32, 32, 3)[source]¶ Returns 4 colored 32x32 test images, one is structured increasing numbers, an images with lines of a cartoon face, and two complex images of people.
- CommandLine:
python -m wbia_cnn.utils –test-testdata_imglist –show
Example
>>> # ENABLE_DOCTEST >>> from wbia_cnn.utils import * # NOQA >>> (img_list, width, height, channels) = testdata_imglist() >>> ut.quit_if_noshow() >>> import plottool as pt >>> pt.imshow(img_list[0], pnum=(2, 2, 1)) >>> pt.imshow(img_list[1], pnum=(2, 2, 2)) >>> pt.imshow(img_list[2], pnum=(2, 2, 3)) >>> pt.imshow(img_list[3], pnum=(2, 2, 4)) >>> ut.show_if_requested()
-
wbia_cnn.utils.
train_test_split
(X, y, eval_size, data_per_label=1, shuffle=True)[source]¶ used to split datasets into two parts. Preserves class distributions using Stratified K-Fold sampling
DEPRICATE : prefer the one implemented in dataset
- Parameters
X (ndarray) –
y (ndarray) –
eval_size –
- Returns
(X_train, y_train, X_valid, y_valid)
- Return type
tuple
- CommandLine:
python -m wbia_cnn.utils –test-train_test_split
Example
>>> # DISABLE_DOCTEST >>> from wbia_cnn.utils import * # NOQA >>> # build test data >>> data, labels, data_per_label = testdata_xy() >>> X = data >>> y = labels >>> eval_size = .2 >>> # execute function >>> (X_train, y_train, X_valid, y_valid) = train_test_split(X, y, eval_size, data_per_label) >>> # verify results >>> result = str((X_train, y_train, X_valid, y_valid)) >>> print(result)
Module contents¶
-
wbia_cnn.
IMPORT_TUPLES
= [('ibsplugin', None), ('models', None), ('process', None), ('netrun', None), ('utils', None)]¶ Regen Command: cd /home/joncrall/code/wbia_cnn/wbia_cnn makeinit.py -x _grave old_test old_models old_main sandbox
-
wbia_cnn.
reassign_submodule_attributes
(verbose=True)[source]¶ why reloading all the modules doesnt do this I don’t know
-
wbia_cnn.
rrrr
(verbose=True)¶ Reloads wbia_cnn and submodules