当前位置: 首页>>代码示例>>Python>>正文


Python objectives.categorical_accuracy方法代码示例

本文整理汇总了Python中lasagne.objectives.categorical_accuracy方法的典型用法代码示例。如果您正苦于以下问题:Python objectives.categorical_accuracy方法的具体用法?Python objectives.categorical_accuracy怎么用?Python objectives.categorical_accuracy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lasagne.objectives的用法示例。


在下文中一共展示了objectives.categorical_accuracy方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: build_model

# 需要导入模块: from lasagne import objectives [as 别名]
# 或者: from lasagne.objectives import categorical_accuracy [as 别名]
def build_model(self):
        
        import theano.tensor as T
        self.x = T.ftensor4('x')
        self.y = T.lvector('y')
        self.lr = T.scalar('lr')
        
        net = build_model_vgg16(input_shape=(None, 3, 224, 224), verbose=self.verbose)
        self.output_layer = net['prob']
        
        from lasagne.layers import get_output
        self.output = lasagne.layers.get_output(self.output_layer, self.x, deterministic=False)
        self.cost = lasagne.objectives.categorical_crossentropy(self.output, self.y).mean()
        from lasagne.objectives import categorical_accuracy
        self.error = 1-categorical_accuracy(self.output, self.y, top_k=1).mean()
        self.error_top_5 = 1-categorical_accuracy(self.output, self.y, top_k=5).mean() 
开发者ID:uoguelph-mlrg,项目名称:Theano-MPI,代码行数:18,代码来源:vgg16.py

示例2: compile_val

# 需要导入模块: from lasagne import objectives [as 别名]
# 或者: from lasagne.objectives import categorical_accuracy [as 别名]
def compile_val(self):

        if self.verbose: print('compiling validation function...')
        
        import theano
        
        from lasagne.layers import get_output
        
        output_val = lasagne.layers.get_output(self.output_layer, self.x, deterministic=True)
        
        from lasagne.objectives import categorical_accuracy, categorical_crossentropy
        
        cost = categorical_crossentropy(output_val, self.y).mean()
        error = 1-categorical_accuracy(output_val, self.y, top_k=1).mean()
        error_top_5 = 1-categorical_accuracy(output_val, self.y, top_k=5).mean()
        
        self.val_fn=  theano.function([self.subb_ind], [cost,error,error_top_5], updates=[], 
                                          givens=[(self.x, self.shared_x_slice),
                                                  (self.y, self.shared_y_slice)]
                                                                ) 
开发者ID:uoguelph-mlrg,项目名称:Theano-MPI,代码行数:22,代码来源:vgg16.py

示例3: build_model

# 需要导入模块: from lasagne import objectives [as 别名]
# 或者: from lasagne.objectives import categorical_accuracy [as 别名]
def build_model(self):
        
        import theano.tensor as T
        self.x = T.ftensor4('x')
        self.y = T.lvector('y')
        self.lr = T.scalar('lr')
        
        net = build_model_resnet50(input_shape=(None, 3, 224, 224))
        
        if self.verbose: print('Total number of layers:', len(lasagne.layers.get_all_layers(net['prob'])))
        
        self.output_layer = net['prob']
        
        from lasagne.layers import get_output
        self.output = lasagne.layers.get_output(self.output_layer, self.x, deterministic=False)
        self.cost = lasagne.objectives.categorical_crossentropy(self.output, self.y).mean()
        from lasagne.objectives import categorical_accuracy
        self.error = 1-categorical_accuracy(self.output, self.y, top_k=1).mean()
        self.error_top_5 = 1-categorical_accuracy(self.output, self.y, top_k=5).mean() 
开发者ID:uoguelph-mlrg,项目名称:Theano-MPI,代码行数:21,代码来源:resnet50.py

示例4: build_model

# 需要导入模块: from lasagne import objectives [as 别名]
# 或者: from lasagne.objectives import categorical_accuracy [as 别名]
def build_model(self):
        
        import theano.tensor as T
        self.x = T.ftensor4('x')
        self.y = T.lvector('y')
        self.lr = T.scalar('lr')
        
        net = build_model_resnet152(input_shape=(None, 3, 224, 224))
        
        self.output_layer = net['prob']
        
        from lasagne.layers import get_output
        self.output = lasagne.layers.get_output(self.output_layer, self.x, deterministic=False)
        self.cost = lasagne.objectives.categorical_crossentropy(self.output, self.y).mean()
        from lasagne.objectives import categorical_accuracy
        self.error = 1-categorical_accuracy(self.output, self.y, top_k=1).mean()
        self.error_top_5 = 1-categorical_accuracy(self.output, self.y, top_k=5).mean() 
开发者ID:uoguelph-mlrg,项目名称:Theano-MPI,代码行数:19,代码来源:resnet152_outdated.py

示例5: calc_accuracy

# 需要导入模块: from lasagne import objectives [as 别名]
# 或者: from lasagne.objectives import categorical_accuracy [as 别名]
def calc_accuracy(prediction, targets):

    #we can use the lasagne objective categorical_accuracy to determine the top1 single label accuracy
    a = T.mean(objectives.categorical_accuracy(prediction, targets, top_k=1))
    
    return a 
开发者ID:kahst,项目名称:AcousticEventDetection,代码行数:8,代码来源:AED_train.py

示例6: calc_accuracy

# 需要导入模块: from lasagne import objectives [as 别名]
# 或者: from lasagne.objectives import categorical_accuracy [as 别名]
def calc_accuracy(prediction, targets):

    # We can use the lasagne objective categorical_accuracy to determine the top1 single label accuracy
    a = T.mean(objectives.categorical_accuracy(prediction, targets, top_k=1))
    
    return a 
开发者ID:kahst,项目名称:BirdCLEF-Baseline,代码行数:8,代码来源:lasagne_net.py

示例7: __init__

# 需要导入模块: from lasagne import objectives [as 别名]
# 或者: from lasagne.objectives import categorical_accuracy [as 别名]
def __init__(self):

        # Define inputs
        input_var = T.ftensor4('input_var')  # input images (batchx3x64x64)
        labels_classifier_var = T.ivector('labels_classifier_var')  # labels for images
        labels_domain_var = T.ivector('labels_domain_var')  # labels for domain (1 for source, 0 for target)
        learning_rate = T.fscalar('learning_rate')

        # Define classifier networks
        network_classifier = self.network_classifier(input_var)
        network_discriminator = self.network_discriminator(network_classifier['classifier/pool1'])

        # Define outputs
        prediction_classifier = get_output(network_classifier['classifier/output'])  # prob image classification
        prediction_discriminator = get_output(network_discriminator['discriminator/output'])  # prob image domain (should be 1 for source)

        # Define losses (objectives)
        loss_classifier_only = T.mean(categorical_crossentropy(prediction_classifier, labels_classifier_var) * labels_domain_var)
        loss_discriminator = T.mean(categorical_crossentropy(prediction_discriminator, labels_domain_var))
        loss_classifier = loss_classifier_only - loss_discriminator

        # Define performance
        perf_classifier_only = categorical_accuracy(prediction_classifier, labels_classifier_var).mean()
        perf_discriminator = categorical_accuracy(prediction_discriminator, labels_domain_var).mean()

        # Define params
        params_classifier = lasagne.layers.get_all_params(network_classifier['classifier/output'], trainable=True)
        params_discriminator = lasagne.layers.get_all_params(network_discriminator['discriminator/output'], trainable=True)
        params_discriminator = [param for param in params_discriminator if 'discriminator' in param.name]

        # Define updates
        updates_classifier = lasagne.updates.adam(loss_classifier, params_classifier, learning_rate=learning_rate)
        updates_classifier_only = lasagne.updates.adam(loss_classifier_only, params_classifier, learning_rate=learning_rate)
        updates_discriminator = lasagne.updates.adam(loss_discriminator, params_discriminator, learning_rate=learning_rate)

        # Define training functions
        self.train_fn_classifier = theano.function(
            [input_var, labels_classifier_var, labels_domain_var, learning_rate],
            [loss_classifier, loss_classifier_only, prediction_classifier],
            updates=updates_classifier)
        self.train_fn_classifier_only = theano.function(
            [input_var, labels_classifier_var, labels_domain_var, learning_rate],
            [loss_classifier, loss_classifier_only, prediction_classifier],
            updates=updates_classifier_only)
        self.train_fn_discriminator = theano.function(
            [input_var, labels_domain_var, learning_rate],
            [loss_discriminator, prediction_discriminator],
            updates=updates_discriminator)

        # Define validation functions
        self.valid_fn_classifier = theano.function(
            [input_var, labels_classifier_var],
            [perf_classifier_only, prediction_classifier])

        self.valid_fn_discriminator = theano.function(
            [input_var, labels_domain_var],
            [perf_discriminator, prediction_discriminator]) 
开发者ID:davidtellez,项目名称:adda_mnist64,代码行数:59,代码来源:adda_network.py


注:本文中的lasagne.objectives.categorical_accuracy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。