def main(model_folder):
    """
    Parameters
    ----------
    model_folder : str
        Path to a folder in which a model (json file) is.
    """
    a = yaml.load(open(utils.get_latest_in_folder(model_folder, ".json")))

    layers = []
    filenames = ["model.yml", "input_semantics.csv", "output_semantics.csv",
                 "preprocessing.yml", "features.yml"]

    # Create input_semantics.csv
    inputs = a['layers'][0]['_props']['n_visible']
    with open('input_semantics.csv', 'wb') as csvfile:
        spamwriter = csv.writer(csvfile, delimiter=';',
                                quotechar='|', quoting=csv.QUOTE_MINIMAL)
        for row in range(inputs):
            spamwriter.writerow(["inputs %i" % row])

    # Create output_semantics.csv
    outputs = a['layers'][-1]['_props']['n_hidden']
    create_output_semantics(model_folder, outputs)

    # Write layers
    for layer_index, layer in enumerate(a['layers']):
        W = _as_ndarray(layer['params']['W'])
        Wfile = h5py.File('W%i.hdf5' % layer_index, 'w')
        Wfile.create_dataset(Wfile.id.name, data=W)
        Wfile.close()

        b = _as_ndarray(layer['params']['b'])
        bfile = h5py.File('b%i.hdf5' % layer_index, 'w')
        bfile.create_dataset(bfile.id.name, data=b)
        bfile.close()

        activation = layer['_props']['activation']
        activation = activation.replace('sigmoid', 'Sigmoid')
        activation = activation.replace('softmax', 'Softmax')
        layers.append({'W': {'size': list(W.shape),
                             'filename': 'W%i.hdf5' % layer_index},
                       'b': {'size': list(b.shape),
                             'filename': 'b%i.hdf5' % layer_index},
                       'activation': activation})
        filenames.append('W%i.hdf5' % layer_index)
        filenames.append('b%i.hdf5' % layer_index)

    model = {'type': 'mlp', 'layers': layers}

    with open("model.yml", 'w') as f:
        yaml.dump(model, f, default_flow_style=False)

    logging.info("Get preprocessing.yml")
    # Get model folder
    model_description_file = os.path.join(model_folder, "info.yml")
    with open(model_description_file, 'r') as ymlfile:
        model_description = yaml.load(ymlfile)

    # Get feature folder
    feature_description_file = os.path.join(utils.get_project_root(),
                                            model_description["data-source"],
                                            "info.yml")
    with open(feature_description_file, 'r') as ymlfile:
        feature_description = yaml.load(ymlfile)

    with open("features.yml", 'w') as f:
        yaml.dump(feature_description, f, default_flow_style=False)

    # Get preprocessing folder
    preprocessing_description_file = os.path.join(utils.get_project_root(),
                                                  feature_description["data-source"],
                                                  "info.yml")
    with open(preprocessing_description_file, 'r') as ymlfile:
        preprocessing_description = yaml.load(ymlfile)

    with open("preprocessing.yml", 'w') as f:
        yaml.dump(preprocessing_description, f, default_flow_style=False)

    with tarfile.open("model.tar", "w:") as tar:
        for name in filenames:
            tar.add(name)

    # Remove temporary files which are now in tar file
    for filename in filenames:
        os.remove(filename)
def main ( model_folder ) : a = yaml . load ( open ( utils . get_latest_in_folder ( model_folder , ".json" ) ) ) layers = [ ] filenames = [ "model.yml" , "input_semantics.csv" , "output_semantics.csv" , "preprocessing.yml" , "features.yml" ] inputs = a [ 'layers' ] [ 0 ] [ '_props' ] [ 'n_visible' ] with open ( 'input_semantics.csv' , 'wb' ) as csvfile : spamwriter = csv . writer ( csvfile , delimiter = ';' , quotechar = '|' , quoting = csv . QUOTE_MINIMAL ) for row in range ( inputs ) : spamwriter . writerow ( [ "inputs %i" % row ] ) outputs = a [ 'layers' ] [ - 1 ] [ '_props' ] [ 'n_hidden' ] create_output_semantics ( model_folder , outputs ) for layer_index , layer in enumerate ( a [ 'layers' ] ) : W = _as_ndarray ( layer [ 'params' ] [ 'W' ] ) Wfile = h5py . File ( 'W%i.hdf5' % layer_index , 'w' ) Wfile . create_dataset ( Wfile . id . name , data = W ) Wfile . close ( ) b = _as_ndarray ( layer [ 'params' ] [ 'b' ] ) bfile = h5py . File ( 'b%i.hdf5' % layer_index , 'w' ) bfile . create_dataset ( bfile . id . name , data = b ) bfile . close ( ) activation = layer [ '_props' ] [ 'activation' ] activation = activation . replace ( 'sigmoid' , 'Sigmoid' ) activation = activation . replace ( 'softmax' , 'Softmax' ) layers . append ( { 'W' : { 'size' : list ( W . shape ) , 'filename' : 'W%i.hdf5' % layer_index } , 'b' : { 'size' : list ( b . shape ) , 'filename' : 'b%i.hdf5' % layer_index } , 'activation' : activation } ) filenames . append ( 'W%i.hdf5' % layer_index ) filenames . append ( 'b%i.hdf5' % layer_index ) model = { 'type' : 'mlp' , 'layers' : layers } with open ( "model.yml" , 'w' ) as f : yaml . dump ( model , f , default_flow_style = False ) logging . info ( "Get preprocessing.yml" ) model_description_file = os . path . join ( model_folder , "info.yml" ) with open ( model_description_file , 'r' ) as ymlfile : model_description = yaml . load ( ymlfile ) feature_description_file = os . path . join ( utils . get_project_root ( ) , model_description [ "data-source" ] , "info.yml" ) with open ( feature_description_file , 'r' ) as ymlfile : feature_description = yaml . load ( ymlfile ) with open ( "features.yml" , 'w' ) as f : yaml . dump ( feature_description , f , default_flow_style = False ) preprocessing_description_file = os . path . join ( utils . get_project_root ( ) , feature_description [ "data-source" ] , "info.yml" ) with open ( preprocessing_description_file , 'r' ) as ymlfile : preprocessing_description = yaml . load ( ymlfile ) with open ( "preprocessing.yml" , 'w' ) as f : yaml . dump ( preprocessing_description , f , default_flow_style = False ) with tarfile . open ( "model.tar" , "w:" ) as tar : for name in filenames : tar . add ( name ) for filename in filenames : os . remove ( filename )
Parameters
    ----------
    model_folder : str
        Path to a folder in which a model (json file) is.