Пример #1
0
def run(name, epochs=100, verbose=1, limit_data=False, dataset_type='cifar10'):
    try:
        import keras
        import tensorflow as tf
        os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
        from Config import MyConfig
        from Model import MyModel
        from keras.utils.generic_utils import get_custom_objects
        from Model import IdentityConv, GroupIdentityConv

        get_custom_objects()['IdentityConv'] = IdentityConv
        get_custom_objects()['GroupIdentityConv'] = GroupIdentityConv

        config = tf.ConfigProto()
        config.gpu_options.allow_growth = True
        sess = tf.Session(config=config)
        with sess.as_default():
            config = MyConfig(name=name,
                              epochs=epochs,
                              verbose=verbose,
                              clean=False,
                              limit_data=limit_data,
                              dataset_type=dataset_type)
            # device = 0
            # with tf.device(device):
            model = MyModel(config=config,
                            model=keras.models.load_model(config.model_path))
            logger.debug('model {} start fit epochs {}'.format(name, epochs))
            score = model.comp_fit_eval()
            keras.models.save_model(model.model, model.config.model_path)
            return name, score
    except Exception as inst:
        print 'INST is'
        print str(inst)
        errors = [
            'ResourceExhaustedError', 'Resource exhausted: OOM', 'OOM',
            'Failed to create session', 'CUDNN_STATUS_INTERNAL_ERROR', 'Chunk',
            'CUDA_ERROR_OUT_OF_MEMORY'
        ]
        for error in errors:
            if error in str(inst):
                return NOMEM, NOMEM
        return None, None
Пример #2
0
        'filters': 64
    }], ["MaxPooling2D", 'maxpooling2d1', {}],
               ["Group", 'Group1', {
                   'filters': 120,
                   'group_num': 2
               }], ["Conv2D_Pooling", 'Conv2D_Pooling_1', {
                   'filters': 139
               }], ["Conv2D", 'Conv2D3', {
                   'filters': 10
               }], ['GlobalMaxPooling2D', 'GlobalMaxPooling2D1', {}],
               ['Activation', 'Activation1', {
                   'activation_type': 'softmax'
               }]]
    graph = MyGraph(model_l)
    before_model = MyModel(config, graph)
    before_model.comp_fit_eval()

    net2net = Net2Net()

    model = net2net.wider_group_conv2d(before_model,
                                       layer_name='Group1',
                                       new_width=174,
                                       config=config.copy('wider_group'))
    model.comp_fit_eval()
    ''' 
    model = net2net.deeper(before_model, config=config.copy('deeper1'))
    model = net2net.deeper_conv2d(before_model, layer_name='Conv2D2', config=config.copy('deeper1'))
    model = net2net.wider_conv2d(model, layer_name='Conv2D2', width_ratio=2, config=config.copy('wide'))
    model.comp_fit_eval()

    model = net2net.wider(model, config=config)