def get_global_species_scorenorm_cachedir(ibs, species_text, ensure=True): """ Args: species_text (str): ensure (bool): Returns: str: species_cachedir CommandLine: python -m ibeis.control.IBEISControl --test-get_global_species_scorenorm_cachedir Example: >>> # ENABLE_DOCTEST >>> from ibeis.control.IBEISControl import * # NOQA >>> import ibeis # NOQA >>> ibs = ibeis.opendb('testdb1') >>> species_text = ibeis.const.TEST_SPECIES.ZEB_GREVY >>> ensure = True >>> species_cachedir = ibs.get_global_species_scorenorm_cachedir(species_text, ensure) >>> resourcedir = ibs.get_ibeis_resource_dir() >>> result = ut.relpath_unix(species_cachedir, resourcedir) >>> print(result) scorenorm/zebra_grevys """ scorenorm_cachedir = join(ibs.get_ibeis_resource_dir(), const.PATH_NAMES.scorenormdir) species_cachedir = join(scorenorm_cachedir, species_text) if ensure: ut.ensurepath(scorenorm_cachedir) ut.ensuredir(species_cachedir) return species_cachedir
def save_if_requested(ibs, subdir): if not ibs.args.save_figures: return #print('[viz] Dumping Image') fpath = ibs.dirs.result_dir if not subdir is None: subdir = utool.sanatize_fname2(subdir) fpath = join(fpath, subdir) utool.ensurepath(fpath) df2.save_figure(fpath=fpath, usetitle=True) df2.reset()
def save_if_requested(ibs, subdir): if not ibs.args.save_figures: return #print('[viz] Dumping Image') fpath = ibs.dirs.result_dir if not subdir is None: subdir = utool.sanitize_fname2(subdir) fpath = join(fpath, subdir) utool.ensurepath(fpath) df2.save_figure(fpath=fpath, usetitle=True) df2.reset()
def __dump_text_report(allres, report_type): if not 'report_type' in vars(): report_type = 'rankres_str' print('[rr2] Dumping textfile: ' + report_type) report_str = allres.__dict__[report_type] # Get directories result_dir = allres.ibs.dirs.result_dir timestamp_dir = join(result_dir, 'timestamped_results') utool.ensurepath(timestamp_dir) utool.ensurepath(result_dir) # Write to timestamp and result dir timestamp = utool.get_timestamp() csv_timestamp_fname = report_type + allres.title_suffix + timestamp + '.csv' csv_timestamp_fpath = join(timestamp_dir, csv_timestamp_fname) csv_fname = report_type + allres.title_suffix + '.csv' csv_fpath = join(result_dir, csv_fname) utool.write_to(csv_fpath, report_str) utool.write_to(csv_timestamp_fpath, report_str)
def testdata_ensure_unconverted_hsdb(): r""" Makes an unconverted test datapath CommandLine: python -m ibeis.dbio.ingest_hsdb --test-testdata_ensure_unconverted_hsdb Example: >>> # SCRIPT >>> from ibeis.dbio.ingest_hsdb import * # NOQA >>> result = testdata_ensure_unconverted_hsdb() >>> print(result) """ import utool as ut assert ut.is_developer(), 'dev function only' # Make an unconverted test database ut.ensurepath('/raid/tests/tmp') ut.delete('/raid/tests/tmp/Frogs') ut.copy('/raid/tests/Frogs', '/raid/tests/tmp/Frogs') hsdb_dir = '/raid/tests/tmp/Frogs' return hsdb_dir
def dump_to_disk(self, dpath, num=None, prefix='temp_img'): import numpy as np import wbia.plottool as pt dpath = ut.ensurepath(dpath) num_zeros = np.ceil(np.log10(len(self.gpath_list))) total = len(self.gpath_list) if num is None: num = total fmtstr = prefix + '_%0' + str(num_zeros) + 'd.jpg' fig = pt.figure(fnum=self.fnum) for index in ut.ProgIter(range(num), lbl='dumping images to disk'): fig = pt.figure(fnum=self.fnum) fig.clf() ax = self._plot_index(index, {'fnum': self.fnum}) fig = ax.figure axes_extents = pt.extract_axes_extents(fig) assert len(axes_extents) == 1, 'more than one axes' extent = axes_extents[0] fpath = ut.unixjoin(dpath, fmtstr % (index)) fig.savefig(fpath, bbox_inches=extent) pt.plt.close(fig)
def make_wordfigures(ibs, metrics, invindex, figdir, wx_sample, wx2_dpath): """ Builds mosaics of patches assigned to words in sample ouptuts them to disk """ from plottool import draw_func2 as df2 import vtool as vt import parse vocabdir = join(figdir, 'vocab_patches2') ut.ensuredir(vocabdir) dump_word_patches(ibs, vocabdir, invindex, wx_sample, metrics) # COLLECTING PART --- collects patches in word folders #vocabdir seldpath = vocabdir + '_selected' ut.ensurepath(seldpath) # stack for show for wx, dpath in ut.progiter(six.iteritems(wx2_dpath), lbl='Dumping Word Images:', num=len(wx2_dpath), freq=1, backspace=False): #df2.rrr() fpath_list = ut.ls(dpath) fname_list = [basename(fpath_) for fpath_ in fpath_list] patch_list = [vt.imread(fpath_) for fpath_ in fpath_list] # color each patch by nid nid_list = [ int(parse.parse('{}_nid={nid}_{}', fname)['nid']) for fname in fname_list ] nid_set = set(nid_list) nid_list = np.array(nid_list) if len(nid_list) == len(nid_set): # no duplicate names newpatch_list = patch_list else: # duplicate names. do coloring sortx = nid_list.argsort() patch_list = np.array(patch_list, dtype=object)[sortx] fname_list = np.array(fname_list, dtype=object)[sortx] nid_list = nid_list[sortx] colors = (255 * np.array(df2.distinct_colors(len(nid_set)))).astype( np.int32) color_dict = dict(zip(nid_set, colors)) wpad, hpad = 3, 3 newshape_list = [ tuple( (np.array(patch.shape) + (wpad * 2, hpad * 2, 0)).tolist()) for patch in patch_list ] color_list = [color_dict[nid_] for nid_ in nid_list] newpatch_list = [ np.zeros(shape) + color[None, None] for shape, color in zip(newshape_list, color_list) ] for patch, newpatch in zip(patch_list, newpatch_list): newpatch[wpad:-wpad, hpad:-hpad, :] = patch #img_list = patch_list #bigpatch = vt.stack_image_recurse(patch_list) #bigpatch = vt.stack_image_list(patch_list, vert=False) bigpatch = vt.stack_square_images(newpatch_list) bigpatch_fpath = join(seldpath, basename(dpath) + '_patches.png') # def _dictstr(dict_): str_ = ut.dict_str(dict_, newlines=False) str_ = str_.replace('\'', '').replace(': ', '=').strip('{},') return str_ figtitle = '\n'.join([ 'wx=%r' % wx, 'stat(pdist): %s' % _dictstr(metrics.wx2_pdist_stats[wx]), 'stat(wdist): %s' % _dictstr(metrics.wx2_wdist_stats[wx]), ]) metrics.wx2_nMembers[wx] df2.figure(fnum=1, doclf=True, docla=True) fig, ax = df2.imshow(bigpatch, figtitle=figtitle) #fig.show() df2.set_figtitle(figtitle) df2.adjust_subplots(top=.878, bottom=0) df2.save_figure(1, bigpatch_fpath)
def make_wordfigures(ibs, metrics, invindex, figdir, wx_sample, wx2_dpath): """ Builds mosaics of patches assigned to words in sample ouptuts them to disk """ from plottool import draw_func2 as df2 import vtool as vt import parse vocabdir = join(figdir, 'vocab_patches2') ut.ensuredir(vocabdir) dump_word_patches(ibs, vocabdir, invindex, wx_sample, metrics) # COLLECTING PART --- collects patches in word folders #vocabdir seldpath = vocabdir + '_selected' ut.ensurepath(seldpath) # stack for show for wx, dpath in ut.progiter(six.iteritems(wx2_dpath), lbl='Dumping Word Images:', num=len(wx2_dpath), freq=1, backspace=False): #df2.rrr() fpath_list = ut.ls(dpath) fname_list = [basename(fpath_) for fpath_ in fpath_list] patch_list = [gtool.imread(fpath_) for fpath_ in fpath_list] # color each patch by nid nid_list = [int(parse.parse('{}_nid={nid}_{}', fname)['nid']) for fname in fname_list] nid_set = set(nid_list) nid_list = np.array(nid_list) if len(nid_list) == len(nid_set): # no duplicate names newpatch_list = patch_list else: # duplicate names. do coloring sortx = nid_list.argsort() patch_list = np.array(patch_list, dtype=object)[sortx] fname_list = np.array(fname_list, dtype=object)[sortx] nid_list = nid_list[sortx] colors = (255 * np.array(df2.distinct_colors(len(nid_set)))).astype(np.int32) color_dict = dict(zip(nid_set, colors)) wpad, hpad = 3, 3 newshape_list = [tuple((np.array(patch.shape) + (wpad * 2, hpad * 2, 0)).tolist()) for patch in patch_list] color_list = [color_dict[nid_] for nid_ in nid_list] newpatch_list = [np.zeros(shape) + color[None, None] for shape, color in zip(newshape_list, color_list)] for patch, newpatch in zip(patch_list, newpatch_list): newpatch[wpad:-wpad, hpad:-hpad, :] = patch #img_list = patch_list #bigpatch = vt.stack_image_recurse(patch_list) #bigpatch = vt.stack_image_list(patch_list, vert=False) bigpatch = vt.stack_square_images(newpatch_list) bigpatch_fpath = join(seldpath, basename(dpath) + '_patches.png') # def _dictstr(dict_): str_ = ut.dict_str(dict_, newlines=False) str_ = str_.replace('\'', '').replace(': ', '=').strip('{},') return str_ figtitle = '\n'.join([ 'wx=%r' % wx, 'stat(pdist): %s' % _dictstr(metrics.wx2_pdist_stats[wx]), 'stat(wdist): %s' % _dictstr(metrics.wx2_wdist_stats[wx]), ]) metrics.wx2_nMembers[wx] df2.figure(fnum=1, doclf=True, docla=True) fig, ax = df2.imshow(bigpatch, figtitle=figtitle) #fig.show() df2.set_figtitle(figtitle) df2.adjust_subplots(top=.878, bottom=0) df2.save_figure(1, bigpatch_fpath)
import os import utool as ut from os.path import basename, join, split # NOQA app_dpath = ut.truepath('~/fsclean_indexes') ut.ensurepath(app_dpath) root = '/media/joncrall/media' class Path(ut.NiceRepr): @property @ut.memoize def abspath(self): return join(self.r, self.n) def __nice__(self): return (self.r, self.n) def __eq__(self, other): return self.abspath == other.abspath def __hash__(self): return hash(self.abspath) @property @ut.memoize def depth(self): return self.abspath.count(os.path.sep)