train.py
def write_model_file(model_file, template_file, train_file, test_file, root_folder, avg_rotations=False,
                     percent_reduc=False,train_file2=None, ratio=None, root_folder2=None, test_root_folder=None):
    '''Writes a model prototxt file based on a provided template file
    with certain placeholders replaced in each MolGridDataLayer.
    For the source parameter, "TRAINFILE" is replaced with train_file
    and "TESTFILE" is replaced with test_file.
    For the root_folder parameter, "DATA_ROOT" is replaced with root_folder,
    unless the layer is TEST phase and test_root_folder is provided,
    then it is replaced with test_root_folder.
    For the source2 parameter, "TRAINFILE2" is replaced with train_file2,
    and in the same layer the source_ratio parameter is set to ratio.
    For the root_folder2 parameter, "DATA_ROOT2" is replaced with root_folder2.
    If the avg_rotations argument is set and the layer is TEST phase,
    the rotate parameter is set to 24.'''
    netparam = NetParameter()
    with open(template_file, 'r') as f:
        prototxt.Merge(f.read(), netparam)
    for layer in netparam.layer:
        if layer.type == "NDimData":
            param = layer.ndim_data_param
        elif layer.type == "MolGridData":
            param = layer.molgrid_data_param
        else:
            continue
        if param.source == 'TRAINFILE':
            param.source = train_file
        if param.source == 'TESTFILE':
            param.source = test_file
        if param.root_folder == 'DATA_ROOT':
            if test_root_folder and 'TEST' in str(layer):
                param.root_folder = test_root_folder
            else:
                param.root_folder = root_folder
        if train_file2 and param.source2 == 'TRAINFILE2':
            param.source2 = train_file2
            param.source_ratio = ratio
        if root_folder2 and param.root_folder2 == 'DATA_ROOT2':
            param.root_folder2 = root_folder2
        if avg_rotations and 'TEST' in str(layer):
            param.rotate = 24 #TODO axial rotations aren't working
            #layer.molgrid_data_param.random_rotation = True
        if percent_reduc and 'TEST' in str(layer) and 'reduced' in model_file:#only shuffle test set for reduced & if percent_reduc was passed
            param.shuffle = True
    with open(model_file, 'w') as f:
        f.write(str(netparam))
Writes a model prototxt file based on a provided template file
    with certain placeholders replaced in each MolGridDataLayer.
    For the source parameter, "TRAINFILE" is replaced with train_file
    and "TESTFILE" is replaced with test_file.
    For the root_folder parameter, "DATA_ROOT" is replaced with root_folder,
    unless the layer is TEST phase and test_root_folder is provided,
    then it is replaced with test_root_folder.
    For the source2 parameter, "TRAINFILE2" is replaced with train_file2,
    and in the same layer the source_ratio parameter is set to ratio.
    For the root_folder2 parameter, "DATA_ROOT2" is replaced with root_folder2.
    If the avg_rotations argument is set and the layer is TEST phase,
    the rotate parameter is set to 24.
Writes a model prototxt file based on a provided template file
with certain placeholders replaced in each MolGridDataLayer.
For the source parameter, "TRAINFILE" is replaced with train_file
and "TESTFILE" is replaced with test_file.
For the root_folder parameter, "DATA_ROOT" is replaced with root_folder,
unless the layer is TEST phase and test_root_folder is provided,
then it is replaced with test_root_folder.
For the source2 parameter, "TRAINFILE2" is replaced with train_file2,
and in the same layer the source_ratio parameter is set to ratio.
Writes a model prototxt file based on a provided template file with certain placeholders replaced in each MolGridDataLayer . For the source parameter " TRAINFILE " is replaced with train_file and " TESTFILE " is replaced with test_file . For the root_folder parameter " DATA_ROOT " is replaced with root_folder unless the layer is TEST phase and test_root_folder is provided then it is replaced with test_root_folder . For the source2 parameter " TRAINFILE2 " is replaced with train_file2 and in the same layer the source_ratio parameter is set to ratio .
def write_model_file(model_file, template_file, train_file, test_file, root_folder, avg_rotations=False,
                     percent_reduc=False,train_file2=None, ratio=None, root_folder2=None, test_root_folder=None):
    netparam = NetParameter()
    with open(template_file, 'r') as f:
        prototxt.Merge(f.read(), netparam)
    for layer in netparam.layer:
        if layer.type == "NDimData":
            param = layer.ndim_data_param
        elif layer.type == "MolGridData":
            param = layer.molgrid_data_param
        else:
            continue
        if param.source == 'TRAINFILE':
            param.source = train_file
        if param.source == 'TESTFILE':
            param.source = test_file
        if param.root_folder == 'DATA_ROOT':
            if test_root_folder and 'TEST' in str(layer):
                param.root_folder = test_root_folder
            else:
                param.root_folder = root_folder
        if train_file2 and param.source2 == 'TRAINFILE2':
            param.source2 = train_file2
            param.source_ratio = ratio
        if root_folder2 and param.root_folder2 == 'DATA_ROOT2':
            param.root_folder2 = root_folder2
        if avg_rotations and 'TEST' in str(layer):
            param.rotate = 24 
        if percent_reduc and 'TEST' in str(layer) and 'reduced' in model_file:
            param.shuffle = True
    with open(model_file, 'w') as f:
        f.write(str(netparam))
def write_model_file ( model_file , template_file , train_file , test_file , root_folder , avg_rotations = False , percent_reduc = False , train_file2 = None , ratio = None , root_folder2 = None , test_root_folder = None ) : netparam = NetParameter ( ) with open ( template_file , 'r' ) as f : prototxt . Merge ( f . read ( ) , netparam ) for layer in netparam . layer : if layer . type == "NDimData" : param = layer . ndim_data_param elif layer . type == "MolGridData" : param = layer . molgrid_data_param else : continue if param . source == 'TRAINFILE' : param . source = train_file if param . source == 'TESTFILE' : param . source = test_file if param . root_folder == 'DATA_ROOT' : if test_root_folder and 'TEST' in str ( layer ) : param . root_folder = test_root_folder else : param . root_folder = root_folder if train_file2 and param . source2 == 'TRAINFILE2' : param . source2 = train_file2 param . source_ratio = ratio if root_folder2 and param . root_folder2 == 'DATA_ROOT2' : param . root_folder2 = root_folder2 if avg_rotations and 'TEST' in str ( layer ) : param . rotate = 24 if percent_reduc and 'TEST' in str ( layer ) and 'reduced' in model_file : param . shuffle = True with open ( model_file , 'w' ) as f : f . write ( str ( netparam ) )
Writes a model prototxt file based on a provided template file
with certain placeholders replaced in each MolGridDataLayer.
Writes a model prototxt file based on a provided template file with certain placeholders replaced in each MolGridDataLayer .
'''Writes a model prototxt file based on a provided template file
    with certain placeholders replaced in each MolGridDataLayer.
    For the source parameter, "TRAINFILE" is replaced with train_file
    and "TESTFILE" is replaced with test_file.
    For the root_folder parameter, "DATA_ROOT" is replaced with root_folder,
    unless the layer is TEST phase and test_root_folder is provided,
    then it is replaced with test_root_folder.
    For the source2 parameter, "TRAINFILE2" is replaced with train_file2,
    and in the same layer the source_ratio parameter is set to ratio.
    For the root_folder2 parameter, "DATA_ROOT2" is replaced with root_folder2.
    If the avg_rotations argument is set and the layer is TEST phase,
    the rotate parameter is set to 24.''' #TODO axial rotations aren't working #layer.molgrid_data_param.random_rotation = True #only shuffle test set for reduced & if percent_reduc was passed
model_file
template_file
train_file
test_file
root_folder
avg_rotations
percent_reduc
train_file2
ratio
root_folder2
test_root_folder