本文整理汇总了Python中utool.flatten函数的典型用法代码示例。如果您正苦于以下问题:Python flatten函数的具体用法?Python flatten怎么用?Python flatten使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了flatten函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_column_keys
def get_column_keys(metadata):
unflat_colname_list = [
[cols.keys() for cols in qaid2_cols.values()]
for qaid2_cols in six.itervalues(metadata.dictstore)
]
colname_list = ut.unique_keep_order(ut.flatten(ut.flatten(unflat_colname_list)))
return colname_list
示例2: delete_contributors
def delete_contributors(ibs, contrib_rowid_list):
r"""
deletes contributors from the database and all information associated
RESTful:
Method: DELETE
URL: /api/contributor/
"""
# TODO: FIXME TESTME
if not ut.QUIET:
print('[ibs] deleting %d contributors' % len(contrib_rowid_list))
config_rowid_list = ut.flatten(ibs.get_contributor_config_rowids(contrib_rowid_list))
# Delete configs (UNSURE IF THIS IS CORRECT)
ibs.delete_configs(config_rowid_list)
# CONTRIBUTORS SHOULD NOT DELETE IMAGES
# Delete encounters
#eid_list = ibs.get_valid_eids()
#eid_config_list = ibs.get_encounter_configid(eid_list)
#valid_list = [config in config_rowid_list for config in eid_config_list ]
#eid_list = ut.compress(eid_list, valid_list)
#ibs.delete_encounters(eid_list)
# Remote image contributors ~~~Delete images~~~~
gid_list = ut.flatten(ibs.get_contributor_gids(contrib_rowid_list))
ibs.set_image_contributor_rowid(gid_list, [None] * len(gid_list))
#ibs.delete_images(gid_list)
# Delete contributors
ibs.db.delete_rowids(const.CONTRIBUTOR_TABLE, contrib_rowid_list)
示例3: get_varied_acfg_labels
def get_varied_acfg_labels(acfg_list, mainkey='_cfgname', checkname=False):
"""
>>> from ibeis.expt.annotation_configs import * # NOQA
"""
#print(ut.list_str(varied_acfg_list, nl=2))
for acfg in acfg_list:
assert acfg['qcfg'][mainkey] == acfg['dcfg'][mainkey], (
'should be the same for now')
cfgname_list = [acfg['qcfg'][mainkey] for acfg in acfg_list]
if checkname and ut.allsame(cfgname_list):
cfgname_list = [None] * len(cfgname_list)
# Hack to make common params between q and d appear the same
_acfg_list = [compress_aidcfg(acfg) for acfg in acfg_list]
flat_acfg_list = flatten_acfg_list(_acfg_list)
nonvaried_dict, varied_acfg_list = ut.partition_varied_cfg_list(
flat_acfg_list)
SUPER_HACK = True
if SUPER_HACK:
# SUPER HACK, recompress remake the varied list after knowing what is varied
_varied_keys = list(set(ut.flatten(
[list(ut.flatten(
[list(x.keys())
for x in unflatten_acfgdict(cfg).values()]
)) for cfg in varied_acfg_list]
)))
_acfg_list = [
compress_aidcfg(acfg, force_noncommon=_varied_keys)
for acfg in acfg_list]
flat_acfg_list = flatten_acfg_list(_acfg_list)
nonvaried_dict, varied_acfg_list = ut.partition_varied_cfg_list(
flat_acfg_list)
shortened_cfg_list = [
#{shorten_to_alias_labels(key): val for key, val in _dict.items()}
ut.map_dict_keys(shorten_to_alias_labels, _dict)
for _dict in varied_acfg_list]
nonlbl_keys = ut.INTERNAL_CFGKEYS
nonlbl_keys = [prefix + key for key in nonlbl_keys
for prefix in ['', 'q', 'd']]
# hack for sorting by q/d stuff first
def get_key_order(cfg):
keys = [k for k in cfg.keys() if k not in nonlbl_keys]
sortorder = [2 * k.startswith('q') + 1 * k.startswith('d')
for k in keys]
return ut.sortedby(keys, sortorder)[::-1]
cfglbl_list = [
ut.get_cfg_lbl(cfg, name, nonlbl_keys, key_order=get_key_order(cfg))
for cfg, name in zip(shortened_cfg_list, cfgname_list)]
if checkname:
cfglbl_list = [x.lstrip(':') for x in cfglbl_list]
return cfglbl_list
示例4: _build_inverted_descriptor_index
def _build_inverted_descriptor_index(aid_list, desc_list):
"""
Stacks descriptors into a flat structure and returns inverse mapping from
flat database descriptor indexes (dx) to annotation ids (aid) and feature
indexes (fx). Feature indexes are w.r.t. annotation indexes.
Output:
dx2_desc - flat descriptor stack
dx2_aid - inverted index into annotations
dx2_fx - inverted index into features
# Example with 2D Descriptors
>>> from ibeis.model.hots.hots_nn_index import * # NOQA
>>> from ibeis.model.hots.hots_nn_index import _build_inverted_descriptor_index
>>> DESC_TYPE = np.uint8
>>> aid_list = [1, 2, 3, 4, 5]
>>> desc_list = [
... np.array([[0, 0], [0, 1]], dtype=DESC_TYPE),
... np.array([[5, 3], [2, 30], [1, 1]], dtype=DESC_TYPE),
... np.empty((0, 2), dtype=DESC_TYPE),
... np.array([[5, 3], [2, 30], [1, 1]], dtype=DESC_TYPE),
... np.array([[3, 3], [42, 42], [2, 6]], dtype=DESC_TYPE),
... ]
>>> dx2_desc, dx2_aid, dx2_fx = _build_inverted_descriptor_index(aid_list, desc_list)
>>> print(repr(dx2_desc.T))
array([[ 0, 0, 5, 2, 1, 5, 2, 1, 3, 42, 2],
[ 0, 1, 3, 30, 1, 3, 30, 1, 3, 42, 6]], dtype=uint8)
>>> print(repr(dx2_aid))
array([1, 1, 2, 2, 2, 4, 4, 4, 5, 5, 5])
>>> print(repr(dx2_fx))
array([0, 1, 0, 1, 2, 0, 1, 2, 0, 1, 2])
cdef:
list aid_list, desc_list
long nFeat, aid
iter aid_nFeat_iter, nFeat_iter, _ax2_aid, _ax2_fx
np.ndarray dx2_aid, dx2_fx, dx2_desc
"""
# Build inverted index of (aid, fx) pairs
aid_nFeat_iter = zip(aid_list, map(len, desc_list))
nFeat_iter = map(len, desc_list)
# generate aid inverted index for each feature in each annotation
_ax2_aid = ([aid] * nFeat for (aid, nFeat) in aid_nFeat_iter)
# Avi: please test the timing of the lines neighboring this statement.
#_ax2_aid = ([aid] * nFeat for (aid, nFeat) in aid_nFeat_iter)
# generate featx inverted index for each feature in each annotation
_ax2_fx = (range(nFeat) for nFeat in nFeat_iter)
# Flatten generators into the inverted index
#dx2_aid = np.array(list(chain.from_iterable(_ax2_aid)))
#dx2_fx = np.array(list(chain.from_iterable(_ax2_fx)))
dx2_aid = np.array(utool.flatten(_ax2_aid))
dx2_fx = np.array(utool.flatten(_ax2_fx))
# Stack descriptors into numpy array corresponding to inverted inexed
# This might throw a MemoryError
dx2_desc = np.vstack(desc_list)
return dx2_desc, dx2_aid, dx2_fx
示例5: get_varied_params_list
def get_varied_params_list(test_cfg_name_list):
vary_dicts = get_vary_dicts(test_cfg_name_list)
dict_comb_list = [utool.all_dict_combinations(dict_) for dict_ in vary_dicts]
dict_comb_lbls = [utool.all_dict_combinations_lbls(dict_) for dict_ in vary_dicts]
# Append testname
dict_comb_lbls = [[name_lbl + lbl for lbl in comb_lbls] for name_lbl, comb_lbls in izip(test_cfg_name_list, dict_comb_lbls)]
varied_params_list = utool.flatten(dict_comb_list) # [comb for dict_comb in dict_comb_list for comb in dict_comb]
varied_param_lbls = utool.flatten(dict_comb_lbls)
return varied_params_list, varied_param_lbls
示例6: test_incremental_add
def test_incremental_add(ibs):
r"""
Args:
ibs (IBEISController):
CommandLine:
python -m ibeis.algo.hots._neighbor_experiment --test-test_incremental_add
Example:
>>> # DISABLE_DOCTEST
>>> from ibeis.algo.hots.neighbor_index_cache import * # NOQA
>>> import ibeis
>>> ibs = ibeis.opendb('PZ_MTEST')
>>> result = test_incremental_add(ibs)
>>> print(result)
"""
import ibeis
sample_aids = ibeis.testdata_aids(a='default:pername=1,mingt=2')
aids1 = sample_aids[::2]
aids2 = sample_aids[0:5]
aids3 = sample_aids[:-1] # NOQA
daid_list = aids1 # NOQA
qreq_ = ibs.new_query_request(aids1, aids1)
nnindexer1 = neighbor_index_cache.request_ibeis_nnindexer(ibs.new_query_request(aids1, aids1)) # NOQA
nnindexer2 = neighbor_index_cache.request_ibeis_nnindexer(ibs.new_query_request(aids2, aids2)) # NOQA
# TODO: SYSTEM use visual uuids
#daids_hashid = qreq_.ibs.get_annot_hashid_visual_uuid(daid_list) # get_internal_data_hashid()
items = ibs.get_annot_visual_uuids(aids3)
uuid_map_fpath = neighbor_index_cache.get_nnindexer_uuid_map_fpath(qreq_)
candidate_uuids = neighbor_index_cache.read_uuid_map(uuid_map_fpath, 0)
candidate_sets = candidate_uuids
covertup = ut.greedy_max_inden_setcover(candidate_sets, items)
uncovered_items, covered_items_list, accepted_keys = covertup
covered_items = ut.flatten(covered_items_list)
covered_aids = sorted(ibs.get_annot_aids_from_visual_uuid(covered_items))
uncovered_aids = sorted(ibs.get_annot_aids_from_visual_uuid(uncovered_items))
nnindexer3 = neighbor_index_cache.request_ibeis_nnindexer(ibs.new_query_request(uncovered_aids, uncovered_aids)) # NOQA
# TODO: SYSTEM use visual uuids
#daids_hashid = qreq_.ibs.get_annot_hashid_visual_uuid(daid_list) # get_internal_data_hashid()
items = ibs.get_annot_visual_uuids(sample_aids)
uuid_map_fpath = neighbor_index_cache.get_nnindexer_uuid_map_fpath(qreq_)
#contextlib.closing(shelve.open(uuid_map_fpath)) as uuid_map:
candidate_uuids = neighbor_index_cache.read_uuid_map(uuid_map_fpath, 0)
candidate_sets = candidate_uuids
covertup = ut.greedy_max_inden_setcover(candidate_sets, items)
uncovered_items, covered_items_list, accepted_keys = covertup
covered_items = ut.flatten(covered_items_list)
covered_aids = sorted(ibs.get_annot_aids_from_visual_uuid(covered_items)) # NOQA
uncovered_aids = sorted(ibs.get_annot_aids_from_visual_uuid(uncovered_items))
示例7: __init__
def __init__(fstack, ibs, aid_list, config=None):
ax2_vecs = ibs.depc_annot.d.get_feat_vecs(aid_list, config=config)
fstack.config = config
fstack.ibs = ibs
fstack.ax2_aid = aid_list
fstack.ax2_nFeat = [len(vecs) for vecs in ax2_vecs]
fstack.idx2_fxs = ut.flatten([list(range(num)) for num in fstack.ax2_nFeat])
fstack.idx2_axs = ut.flatten([[ax] * num for ax, num in enumerate(fstack.ax2_nFeat)])
fstack.idx2_vec = np.vstack(ax2_vecs)
#fstack.idx2_fxs = vt.atleast_nd(fstack.idx2_fxs, 2)
#fstack.idx2_axs = vt.atleast_nd(fstack.idx2_axs, 2)
fstack.num_feat = sum(fstack.ax2_nFeat)
示例8: intersect_hack
def intersect_hack():
failed = testres.rank_mat > 0
colx2_failed = [np.nonzero(failed_col)[0] for failed_col in failed.T]
#failed_col2_only = np.setdiff1d(colx2_failed[1], colx2_failed[0])
#failed_col2_only_aids = ut.take(testres.qaids, failed_col2_only)
failed_col1_only = np.setdiff1d(colx2_failed[0], colx2_failed[1])
failed_col1_only_aids = ut.take(testres.qaids, failed_col1_only)
gt_aids1 = ibs.get_annot_groundtruth(failed_col1_only_aids, daid_list=testres.cfgx2_qreq_[0].daids)
gt_aids2 = ibs.get_annot_groundtruth(failed_col1_only_aids, daid_list=testres.cfgx2_qreq_[1].daids)
qaids_expt = failed_col1_only_aids
gt_avl_aids1 = ut.flatten(gt_aids1)
gt_avl_aids2 = list(set(ut.flatten(gt_aids2)).difference(gt_avl_aids1))
ibs.print_annotconfig_stats(qaids_expt, gt_avl_aids1)
ibs.print_annotconfig_stats(qaids_expt, gt_avl_aids2)
#jsontext = ut.to_json({
# 'qaids': list(qaids_expt),
# 'dinclude_aids1': list(gt_aids_expt1),
# 'dinclude_aids2': list(gt_aids_expt2),
#})
#annotation_configs.varysize_pzm
#from ibeis.expt import annotation_configs
acfg = testres.acfg_list[0]
import copy
acfg1 = copy.deepcopy(acfg)
acfg2 = copy.deepcopy(acfg)
acfg1['qcfg']['min_pername'] = None
acfg2['qcfg']['min_pername'] = None
acfg1['dcfg']['min_pername'] = None
acfg2['dcfg']['min_gt_per_name'] = None
acfg1['qcfg']['default_aids'] = qaids_expt
acfg1['dcfg']['gt_avl_aids'] = gt_avl_aids1
acfg2['qcfg']['default_aids'] = qaids_expt
acfg2['dcfg']['gt_avl_aids'] = gt_avl_aids2
from ibeis.init import filter_annots
from ibeis.expt import experiment_helpers
annots1 = filter_annots.expand_acfgs(ibs, acfg1, verbose=True)
annots2 = filter_annots.expand_acfgs(ibs, acfg2, verbose=True)
acfg_name_list = dict( # NOQA
acfg_list=[acfg1, acfg2],
expanded_aids_list=[annots1, annots2],
)
test_cfg_name_list = ['candidacy_k']
cfgdict_list, pipecfg_list = experiment_helpers.get_pipecfg_list(test_cfg_name_list, ibs=ibs)
t1, t2 = testres_list # NOQA
示例9: parse_all_fname_tags
def parse_all_fname_tags(fname):
_tags = [splitext(fname)[0]]
_tags = ut.flatten([t.split('_') for t in _tags])
_tags = ut.flatten([t.split('.') for t in _tags])
_tags = [t.lower() for t in _tags]
_tags = [tag_alias_map.get(t, t) for t in _tags]
for key, vals in regex_alias_map.items():
pat = ut.regex_or(vals)
_tags = [key if re.match(pat, t) else t for t in _tags]
pat = ut.regex_or(invalid_tag_patterns)
_tags = [t for t in _tags if not re.match(pat, t)]
_tags = ut.unique_ordered(_tags)
return _tags
示例10: make_ibeis_matching_graph
def make_ibeis_matching_graph(ibs, qaid_list, daids_list, scores_list):
print('make_ibeis_matching_graph')
aid1_list = ut.flatten([[qaid] * len(daids) for qaid, daids in zip(qaid_list, daids_list)])
aid2_list = ut.flatten(daids_list)
unique_aids = list(set(aid2_list + qaid_list))
score_list = ut.flatten(scores_list)
# Make a graph between the chips
nodes = list(zip(unique_aids))
edges = list(zip(aid1_list, aid2_list, score_list))
node_lbls = [('aid', 'int')]
edge_lbls = [('weight', 'float')]
netx_graph = make_netx_graph(nodes, edges, node_lbls, edge_lbls)
return netx_graph
示例11: get_name_imgsetids
def get_name_imgsetids(ibs, nid_list):
r"""
RESTful:
Method: GET
URL: /api/name/imgsetids/
"""
import utool as ut
name_aids_list = ibs.get_name_aids(nid_list)
name_aid_list = ut.flatten(name_aids_list)
name_gid_list = ibs.get_annot_gids(name_aid_list)
name_imgsetids_list = ibs.get_image_imgsetids(name_gid_list)
name_imgsetid_list = ut.flatten(name_imgsetids_list)
name_imgsetids = list(set(name_imgsetid_list))
return name_imgsetids
示例12: unnest_data
def unnest_data(data):
unnested_cols = list(zip(ut.take(data, idxs2)))
nested_cols = ut.take(data, idxs1)
grouped_items = [nested_cols, unnested_cols]
groupxs = [idxs1, idxs2]
unflat = ut.ungroup(grouped_items, groupxs, nested_nCols - 1)
return tuple(ut.flatten(unflat))
示例13: get_set_groundfalse
def get_set_groundfalse(ibs, qaids):
# get groundfalse annots relative to the entire set
valid_nids = ibs.get_valid_nids()
qnids = ibs.get_annot_nids(qaids)
nid_list = list(set(valid_nids) - set(qnids))
aids_list = ibs.get_name_aids(nid_list)
return ut.flatten(aids_list)
示例14: test_vsone_verified
def test_vsone_verified(ibs):
"""
hack in vsone-reranking
Example:
>>> # DISABLE_DOCTEST
>>> from ibeis.all_imports import * # NOQA
>>> #reload_all()
>>> from ibeis.algo.hots.automated_matcher import * # NOQA
>>> import ibeis
>>> ibs = ibeis.opendb('PZ_MTEST')
>>> test_vsone_verified(ibs)
"""
import plottool as pt
#qaids = ibs.get_easy_annot_rowids()
nids = ibs.get_valid_nids(filter_empty=True)
grouped_aids_ = ibs.get_name_aids(nids)
grouped_aids = list(filter(lambda x: len(x) > 1, grouped_aids_))
items_list = grouped_aids
sample_aids = ut.flatten(ut.sample_lists(items_list, num=2, seed=0))
qaid2_qres, qreq_ = query_vsone_verified(ibs, sample_aids, sample_aids)
for cm in ut.InteractiveIter(list(six.itervalues(qaid2_qres))):
pt.close_all_figures()
fig = cm.ishow_top(ibs)
fig.show()
示例15: group_review
def group_review():
prefill = request.args.get('prefill', '')
if len(prefill) > 0:
ibs = current_app.ibs
aid_list = ibs.get_valid_aids()
bad_species_list, bad_viewpoint_list = ibs.validate_annot_species_viewpoint_cnn(aid_list)
GROUP_BY_PREDICTION = True
if GROUP_BY_PREDICTION:
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)
else:
candidate_aid_list = [ bad_viewpoint[0] for bad_viewpoint in bad_viewpoint_list]
elif request.args.get('aid_list', None) is not None:
aid_list = request.args.get('aid_list', '')
if len(aid_list) > 0:
aid_list = aid_list.replace('[', '')
aid_list = aid_list.replace(']', '')
aid_list = aid_list.strip().split(',')
candidate_aid_list = [ int(aid_.strip()) for aid_ in aid_list ]
else:
candidate_aid_list = ''
else:
candidate_aid_list = ''
return appf.template(None, 'group_review', candidate_aid_list=candidate_aid_list, mode_list=appf.VALID_TURK_MODES)