예제 #1
0
def tf_freeze_graph(sess: Session,
                    saver: Saver,
                    model_name: str,
                    logdir: str,
                    model_suffix: str = "pb",
                    conf_suffix: str = "pbtxt",
                    checkpoint_suffix: str = "ckpt"):
    """
    python freeze_graph.py --output_graph =./pbs/frozenGraph.pb --output_node_names=genderOut,ageOut --input_binary=true
    """
    input_conf = write_graph(
        sess.graph_def, logdir,
        extsep.join('_'.join((model_name, "graphDef")), conf_suffix))

    input_binary = True
    input_graph = write_graph(sess.graph_def,
                              logdir,
                              extsep.join('_'.join((model_name, "graphDef")),
                                          model_suffix),
                              as_text=False)

    input_checkpoint = saver.save(
        sess, path_join(logdir, extsep.join(model_name, checkpoint_suffix)))

    output_node_names = ""

    output_graph = path_join(
        logdir,
        extsep.join('_'.join((model_name, "frozenGraphDef")), model_suffix))
    freeze_graph(input_graph, "", input_binary, input_checkpoint,
                 output_node_names, "save/restore_all", "save/Const:0",
                 output_graph, True, "")
    return output_graph
예제 #2
0
    def plugin_album(self, songs):

        songs.sort(lambda a, b: cmp(a('~#track'), b('~#track')) or
                                cmp(a('~basename'), b('~basename')) or
                                cmp(a, b))

        chooser = filechooser(save=True, title=songs[0]('album'))
        resp = chooser.run()
        fn = chooser.get_filename()
        chooser.destroy()
        if resp != Gtk.ResponseType.ACCEPT:
            return
        base, ext = splitext(fn)
        if not ext:
            fn = extsep.join([fn, 'tags'])

        global lastfolder
        lastfolder = dirname(fn)
        out = open(fn, 'w')

        for song in songs:
            print>>out, str(song('~basename'))
            keys = song.keys()
            keys.sort()
            for key in keys:
                if key.startswith('~'):
                    continue
                for val in song.list(key):
                    print>>out, '%s=%s' % (key, val.encode('utf-8'))
            print>>out
예제 #3
0
    def plugin_album(self, songs):

        songs.sort(lambda a, b: cmp(a('~#track'), b('~#track')) or
                                cmp(a('~basename'), b('~basename')) or
                                cmp(a, b))

        chooser = filechooser(save=True, title=songs[0]('album'))
        resp = chooser.run()
        fn = chooser.get_filename()
        chooser.destroy()
        if resp != Gtk.ResponseType.ACCEPT:
            return
        base, ext = splitext(fn)
        if not ext:
            fn = extsep.join([fn, 'tags'])

        global lastfolder
        lastfolder = dirname(fn)
        out = open(fn, 'w')

        for song in songs:
            print>>out, str(song('~basename'))
            keys = song.keys()
            keys.sort()
            for key in keys:
                if key.startswith('~'):
                    continue
                for val in song.list(key):
                    print>>out, '%s=%s' % (key, val.encode('utf-8'))
            print>>out
예제 #4
0
def get_abs_template_path(template_name, directory, extension):
    """ Given a template name, a directory, and an extension,
    return the absolute path to the template.  """
    # Get the relative path
    relative_path = join(directory, template_name)
    file_with_ext = template_name

    if extension:
        # If there is a default extension, but no file extension, then add it
        file_name, file_ext = splitext(file_with_ext)
        if not file_ext:
            file_with_ext = extsep.join((file_name, extension.replace(extsep, '')))
            # Rebuild the relative path
            relative_path = join(directory, file_with_ext)

    return abspath(relative_path)
예제 #5
0
 def __init__(self, filename, include_width_in_name=False,
              target=None, motif_file='unknown_motif', genome=None,
              *args, **kwargs):
     fext = splitext(filename)[1].lstrip(extsep)
     if fext == 'bed':
         self.is_bed = True
         self.is_xls = False
     elif fext == 'xls':
         self.is_bed = False
         self.is_xls = True
     else: raise InvalidFileException
     motif_name = sub('\W', '_', abspath(motif_file))
     target = target + sep + motif_name
     super(PeaksFilenameParser, self).__init__(filename,
                                          target = target,
                                          *args, **kwargs)
     self.fasta_file = None
     for file_extension in ['fa', 'fasta', 'FA', 'FASTA']:
         fasta_file = join(self.input_dir,
                         extsep.join([self.protoname, file_extension]))
         debug("Trying", fasta_file)
         if exists(fasta_file):
             self.fasta_file = fasta_file
             debug("Using", fasta_file)
             break
     if self.fasta_file is None:
         warning('Could not find the FASTA file for %s',
                       self.input_file)
         if genome is None:
             raise Usage("Could not find the FASTA file for ", self.input_file,
                         " and no genome was specified")
         else:
             t = try_to_find_genome(genome)
             if t is None:
                 raise Usage("Could not find the FASTA file for ", self.input_file,
                             " and failed to use %s" % genome)
             else:
                 fasta_file = join(self.input_dir, '%s.fa' % self.protoname)
                 debug('Creating FASTA file %s for %s using %s',
                                fasta_file, self.input_file, genome)
                 input_fhd = open(self.input_file, 'rU')
                 fasta_fhd = open(fasta_file, 'w')
                 twobit_reader(t, input_stream=input_fhd,
                               write=fasta_fhd.write)
                 fasta_fhd.close()
                 self.fasta_file = fasta_file
예제 #6
0
def get_abs_template_path(template_name, directory, extension):
    """ Given a template name, a directory, and an extension, return the
    absolute path to the template. """
    # Get the relative path
    relative_path = join(directory, template_name)
    file_with_ext = template_name

    if extension:
        # If there is a default extension, but no file extension, then add it
        file_name, file_ext = splitext(file_with_ext)
        if not file_ext:
            file_with_ext = extsep.join(
                (file_name, extension.replace(extsep, '')))
            # Rebuild the relative path
            relative_path = join(directory, file_with_ext)

    return abspath(relative_path)
예제 #7
0
def main():
    ocl_setup()
    ovx_setup()
    # TODO ogl
    ipp_setup()
    optimized_setup()

    x_train, y_train = get_data()
    x_train = x_train.astype(float32)
    mlp: ml_ANN_MLP = train_mlp(x_train, list(y_train.tolist()))
    time_inference(mlp, x_train)

    model_name = "mobilenet_v2_1.0_96"
    logdir = path_join(pardir, "data", model_name)
    frozen_graph = extsep.join(('_'.join((model_name, "frozen")), "pb"))
    net = read_net_from_tf(model_name, logdir, frozen_graph)

    sample = x_train[0]
    width = uint16(8)
    height = uint16(sample.shape[0] / width)
    dnn_predict(net, (width, height), sample, sort(unique(y_train)))
예제 #8
0
def persistence_filename(this_file_name, sub=None):
    filename_stem = this_file_name.split(sep)[-1].split(extsep)[0]
    qualified_filename_stem = filename_stem if sub is None else '_'.join(
        (filename_stem, sub))
    return extsep.join((qualified_filename_stem, "h5"))
예제 #9
0
def convert(filename):
    content = pd.read_excel(filename).to_csv()
    filename = extsep.join(filename.split(extsep)[:-1]) + extsep + 'csv'
    with open(filename, 'w') as f:
        f.write(content)
예제 #10
0
import json
from os import makedirs, environ
from os.path import extsep, isfile, join as path_join
from getpass import getpass

import requests
from appdirs import user_data_dir
from filelock import FileLock

import acumos
from acumos.exc import AcumosError
from acumos.logging import get_logger
from acumos.utils import load_artifact, dump_artifact

_CONFIG_DIR = user_data_dir('acumos')
_CONFIG_PATH = path_join(_CONFIG_DIR, extsep.join(('config', 'json')))
_LOCK_PATH = path_join(_CONFIG_DIR, extsep.join(('config', 'lock')))

_USERNAME_VAR = 'ACUMOS_USERNAME'
_PASSWORD_VAR = 'ACUMOS_PASSWORD'
_TOKEN_VAR = 'ACUMOS_TOKEN'

logger = get_logger(__name__)
gettoken = getpass


def get_jwt(auth_api):
    '''Returns the jwt string from config or authentication'''
    jwt = environ.get(_TOKEN_VAR)
    if not jwt:
        config = _configuration()