Example #1
0
def dump_code(framework, network_filepath, weight_filepath, dump_filepath,
              dump_tag):
    if network_filepath.endswith('.py'):
        network_filepath = network_filepath[:-3]
    sys.path.insert(0, os.path.dirname(os.path.abspath(network_filepath)))
    MainModel = imp.load_source('MainModel', network_filepath + '.py')
    if framework == 'caffe':
        from mmdnn.conversion.caffe.saver import save_model
    elif framework == 'cntk':
        from mmdnn.conversion.cntk.saver import save_model
    elif framework == 'keras':
        from mmdnn.conversion.keras.saver import save_model
    elif framework == 'mxnet':
        from mmdnn.conversion.mxnet.saver import save_model
    elif framework == 'pytorch':
        from mmdnn.conversion.pytorch.saver import save_model
    elif framework == 'tensorflow':
        from mmdnn.conversion.tensorflow.saver import save_model
        save_model(MainModel, network_filepath, weight_filepath, dump_filepath,
                   dump_tag)
        return 0

    elif framework == 'onnx':
        from mmdnn.conversion.onnx.saver import save_model
    else:
        raise NotImplementedError(
            "{} saver is not finished yet.".format(framework))
    save_model(MainModel, network_filepath, weight_filepath, dump_filepath)

    return 0
Example #2
0
 def start(self):
     print("start to do pytorch to IR")
     self.parse.run(self.save_root)
     print("done! then to do IR to caffe code")
     emitter = CaffeEmitter(
         (self.save['structurepb'], self.save['weights']))
     emitter.run(self.save['caffenetwork'], self.save['caffeweights'],
                 'test')
     print("done! then to do ccode to model")
     MainModel = imp.load_source('MainModel', self.save['caffenetwork'])
     save_model(
         MainModel, self.save['caffenetwork'],
         self.save['caffeweights', self.save['caffemodel'],
                   self.save['caffeproto']])
     print("done!!!!!!")
Example #3
0
    def start(self):
        print("start to do pytorch to IR")
        self.parse.run(self.save_root + self.save_name)
        print("done! then to do IR to caffe code")
        emitter = CaffeEmitter(
            (self.save['structurepb'], self.save['weights']))
        emitter.run(self.save['caffenetwork'], self.save['caffeweights'],
                    'test')
        print("done! then to do ccode to model")
        MainModel = imp.load_source('MainModel', self.save['caffenetwork'])
        save_model(MainModel, self.save['caffenetwork'],
                   self.save['caffeweights'], self.save['caffemodel'])

        print('start to rename inputs')
        lines = open(self.save['caffemodel'] + '.prototxt', 'r').readlines()
        new_lines = rename_input(lines, self.input_shape)
        fp = open(self.save['caffemodel'] + '.prototxt', 'w')
        fp.writelines(new_lines)
        print("^~^^~^^~^^~^")
Example #4
0
def dump_code(framework, network_filepath, weight_filepath, dump_filepath):
    if network_filepath.endswith('.py'):
        network_filepath = network_filepath[:-3]
    MainModel = __import__(network_filepath)
    if framework == 'caffe':
        from mmdnn.conversion.caffe.saver import save_model
    elif framework == 'cntk':
        from mmdnn.conversion.cntk.saver import save_model
    elif framework == 'keras':
        from mmdnn.conversion.keras.saver import save_model
    elif framework == 'mxnet':
        from mmdnn.conversion.mxnet.saver import save_model
    elif framework == 'pytorch':
        from mmdnn.conversion.pytorch.saver import save_model
    elif framework == 'tensorflow':
        from mmdnn.conversion.tensorflow.saver import save_model
    else:
        raise NotImplementedError(
            "{} saver is not finished yet.".format(framework))
    save_model(MainModel, network_filepath, weight_filepath, dump_filepath)
Example #5
0
def dump_code(framework, network_filepath, weight_filepath, dump_filepath):
    if network_filepath.endswith('.py'):
        network_filepath = network_filepath[:-3]
    sys.path.insert(0, os.path.dirname(os.path.abspath(network_filepath)))
    MainModel = __import__(network_filepath)
    if framework == 'caffe':
        from mmdnn.conversion.caffe.saver import save_model
    elif framework == 'cntk':
        from mmdnn.conversion.cntk.saver import save_model
    elif framework == 'keras':
        from mmdnn.conversion.keras.saver import save_model
    elif framework == 'mxnet':
        from mmdnn.conversion.mxnet.saver import save_model
    elif framework == 'pytorch':
        from mmdnn.conversion.pytorch.saver import save_model
    elif framework == 'tensorflow':
        from mmdnn.conversion.tensorflow.saver import save_model
    else:
        raise NotImplementedError("{} saver is not finished yet.".format(framework))
    save_model(MainModel, network_filepath, weight_filepath, dump_filepath)

    return 0