def createPatchTuplesMAP(balL, attr2pat, R, flip=False): """ Sort of creates 'tasks' for groupImagesWorkerMAP, where each task is a tuple of the form: (imgpatch_i, [attrpatch_i, ...], attrval_i, side_i, isflip_i) And you create one task for each side of a voted ballot (i.e. one for side0, another for side1, ...), to figure out the imgorder. Note that there can be multiple exemplar attrpatches. Input: tuple balL: (sidepath_i, ...) dict attr2pat: maps {str attrval: [(str imgpath, obj imgpatch_i), ...]} tuple R: (y1, y2, x1, x2). A 'super' region. Output: ((obj imgpatch_i, [obj attrpatch_i0, ...], str attrval_i, int side_i, int isflip_i), ...) """ pFac = 1 patchTuples = [] for idx in range(len(balL)): balP = balL[idx] I = sh.standardImread(balP, flatten=True) if flip: I = sh.fastFlip(I) (rOut, rOff) = sh.expand(R[0], R[1], R[2], R[3], I.shape[0], I.shape[1], pFac) I1 = I[rOut[0]:rOut[1], rOut[2]:rOut[3]] for attrval, exemplar_pairs in attr2pat.iteritems(): exmpl_patches = [t[1] for t in exemplar_pairs] patchTuples.append((I1, exmpl_patches, attrval, idx, flip)) return patchTuples
def createPatchTuplesMAP(balL,attr2pat,R,flip=False): """ Sort of creates 'tasks' for groupImagesWorkerMAP, where each task is a tuple of the form: (imgpatch_i, [attrpatch_i, ...], attrval_i, side_i, isflip_i) And you create one task for each side of a voted ballot (i.e. one for side0, another for side1, ...), to figure out the imgorder. Note that there can be multiple exemplar attrpatches. Input: tuple balL: (sidepath_i, ...) dict attr2pat: maps {str attrval: [(str imgpath, obj imgpatch_i), ...]} tuple R: (y1, y2, x1, x2). A 'super' region. Output: ((obj imgpatch_i, [obj attrpatch_i0, ...], str attrval_i, int side_i, int isflip_i), ...) """ pFac=1; patchTuples=[]; for idx in range(len(balL)): balP=balL[idx] I=sh.standardImread(balP,flatten=True) if flip: I = sh.fastFlip(I) (rOut,rOff)=sh.expand(R[0],R[1],R[2],R[3],I.shape[0],I.shape[1],pFac) I1=I[rOut[0]:rOut[1],rOut[2]:rOut[3]] for attrval, exemplar_pairs in attr2pat.iteritems(): exmpl_patches = [t[1] for t in exemplar_pairs] patchTuples.append((I1, exmpl_patches, attrval, idx, flip)) return patchTuples
def finalise(config): """Removes files, transfers etc.""" logger = shared.get_logger() logger.info('*** FINALISING ***') working_dir = config['working_dir'] links = [shared.expand(x, config) for x in config['finalise.link']] remove = [shared.expand(x, config) for x in config['finalise.remove']] subdirs = [shared.expand(x, config) for x in config['finalise.create']] copy = [shared.expand(x, config) for x in config['finalise.copy']] move = [shared.expand(x, config) for x in config['finalise.move']] run = [shared.expand(x, config) for x in config['finalise.run']] fulldirs = subdirs for d in fulldirs: if not os.path.exists(d): logger.debug('creating directory %s ' %d) os.mkdir(d) for arg in move: cmd = "mv %s" % arg shared.run_cmd(cmd, config) for arg in copy: cmd = "cp %s" % arg shared.run_cmd(cmd, config) for pattern in links: shared.link(pattern) for cmd in run: shared.run_cmd(cmd, config) for pattern in remove: flist = glob.glob(pattern) for f in flist: if os.path.exists(f): os.remove(f) logger.info('*** DONE FINALISE ***')
def createPatchTuples(I,attr2pat,R,flip=False): """ Only used in templateSSWorker. Note: This is quite different from createPatchTuplesMAP, despite the very similar name. Input: nparray I: dict ATTR2PAT: maps {str attrval: [(str imgpath, nparray patch_i), ...]} tuple R: SuperRegion. Output: tuple PATCHTUPLES. [[I_i, [exmpl_patch_i, ...], str attrval, bool isflip_i], ...] """ pFac=1; if flip: I = sh.fastFlip(I) (rOut,rOff)=sh.expand(R[0],R[1],R[2],R[3],I.shape[0],I.shape[1],pFac) I1=I[rOut[0]:rOut[1],rOut[2]:rOut[3]] patchTuples=[]; for attrval, exmpl_pairs in attr2pat.iteritems(): patches = [t[1] for t in exmpl_pairs] patchTuples.append((I1,patches,attrval,flip)) return patchTuples
def createPatchTuples(I, attr2pat, R, flip=False): """ Only used in templateSSWorker. Note: This is quite different from createPatchTuplesMAP, despite the very similar name. Input: nparray I: dict ATTR2PAT: maps {str attrval: [(str imgpath, nparray patch_i), ...]} tuple R: SuperRegion. Output: tuple PATCHTUPLES. [[I_i, [exmpl_patch_i, ...], str attrval, bool isflip_i], ...] """ pFac = 1 if flip: I = sh.fastFlip(I) (rOut, rOff) = sh.expand(R[0], R[1], R[2], R[3], I.shape[0], I.shape[1], pFac) I1 = I[rOut[0]:rOut[1], rOut[2]:rOut[3]] patchTuples = [] for attrval, exmpl_pairs in attr2pat.iteritems(): patches = [t[1] for t in exmpl_pairs] patchTuples.append((I1, patches, attrval, flip)) return patchTuples
def finalise(config): """Removes files, transfers etc.""" logger = shared.get_logger() logger.info('*** FINALISING ***') working_dir = config['working_dir'] links = [shared.expand(x, config) for x in config['finalise.link']] remove = [shared.expand(x, config) for x in config['finalise.remove']] subdirs = [shared.expand(x, config) for x in config['finalise.create']] copy = [shared.expand(x, config) for x in config['finalise.copy']] move = [shared.expand(x, config) for x in config['finalise.move']] run = [shared.expand(x, config) for x in config['finalise.run']] fulldirs = subdirs for d in fulldirs: if not os.path.exists(d): logger.debug('creating directory %s ' % d) os.mkdir(d) for arg in move: cmd = "mv %s" % arg shared.run_cmd(cmd, config) for arg in copy: cmd = "cp %s" % arg shared.run_cmd(cmd, config) for pattern in links: shared.link(pattern) for cmd in run: shared.run_cmd(cmd, config) for pattern in remove: flist = glob.glob(pattern) for f in flist: if os.path.exists(f): os.remove(f) logger.info('*** DONE FINALISE ***')