首页 \ 问答 \ 它是多重继承吗?如果不是为什么?(Is it a Multiple Inheritance?If not why?)

它是多重继承吗?如果不是为什么?(Is it a Multiple Inheritance?If not why?)

public interface A {
    class Aclass {
        int constants = 100;
        public void display()
        {
            System.out.println("Inside A");
        }
    }
    public void display();

}
public interface B {
    class Bclass {
        int constants = 130;

        public void display() {
            System.out.println("Inside B");
        }
    }
    public void display();
}

public class MultipleInheritance implements A, B {

    @Override
    public void display() {
        A.Aclass a = new A.Aclass();
        System.out.println(a.constants);
        B.Bclass b = new B.Bclass();
        System.out.println(b.constants);
    }

    public static void main(String args[]) {

        new MultipleInheritance().display();
    }
}

虽然它是通过接口而不是通过上下文中的具体类而不是继承任何东西,但仍然不是代码重用,即使保持内部类很难但仍然充当多重继承请用内存表示清除如果可能的话。


public interface A {
    class Aclass {
        int constants = 100;
        public void display()
        {
            System.out.println("Inside A");
        }
    }
    public void display();

}
public interface B {
    class Bclass {
        int constants = 130;

        public void display() {
            System.out.println("Inside B");
        }
    }
    public void display();
}

public class MultipleInheritance implements A, B {

    @Override
    public void display() {
        A.Aclass a = new A.Aclass();
        System.out.println(a.constants);
        B.Bclass b = new B.Bclass();
        System.out.println(b.constants);
    }

    public static void main(String args[]) {

        new MultipleInheritance().display();
    }
}

though it's through interface and not through a concrete class in context to which you are not inheriting anything but still is it not a code reuse even though maintaining a inner classes will be difficult but still it acts as a multiple-inheritance please clearify with memory representation if possible.


原文:https://stackoverflow.com/questions/18631367
更新时间:2021-12-09 10:12

最满意答案

为什么scikit-learn功能不能完成这项工作? 您将所有样本(图像)转发到列车/测试集中,将单热编码转换为标签编码(请参阅链接 ),并将其作为y_pred传递到y_pred 。 你以y_true (单热标签)以类似的方式继续。

示例代码:

import sklearn.metrics as metrics

y_pred_ohe = KerasClassifier.predict(X)  # shape=(n_samples, 12)
y_pred_labels = np.argmax(y_pred_ohe, axis=1)  # only necessary if output has one-hot-encoding, shape=(n_samples)

confusion_matrix = metrics.confusion_matrix(y_true=y_true_labels, y_pred=y_pred_labels)  # shape=(12, 12)

Here's how to get the confusion matrix(or maybe statistics using scikit-learn) for all classes:

1.Predict classes

test_generator = ImageDataGenerator()
test_data_generator = test_generator.flow_from_directory(
    test_data_path, # Put your path here
     target_size=(img_width, img_height),
    batch_size=32,
    shuffle=False)
test_steps_per_epoch = numpy.math.ceil(test_data_generator.samples / test_data_generator.batch_size)

predictions = model.predict_generator(test_data_generator, steps=test_steps_per_epoch)
# Get most likely class
predicted_classes = numpy.argmax(predictions, axis=1)

2.Get ground-truth classes and class-labels

true_classes = test_data_generator.classes
class_labels = list(test_data_generator.class_indices.keys())   

3. Use scikit-learn to get statistics

report = metrics.classification_report(true_classes, predicted_classes, target_names=class_labels)
print(report)    

You can read more here

EDIT: If the above does not work, have a look at this video Create confusion matrix for predictions from Keras model. Probably look through the comments if you have an issue. Or Make predictions with a Keras CNN Image Classifier

相关问答

更多
  • 你是对的:如果你使用16个尺寸为3x3滤镜,你会看到16x3x6重量。 当我使用免费的HDFView工具从这里打开VGG16网络的*.h5文件时,卷积具有以下权重: 32位浮点,64 x 3 x 3 x 3 32位浮点64 对于这一层 Convolution2D(64, 3, 3, activation='relu') 因此,我认为您使用的HDF Explorer错误(这就是我要求更多屏幕截图的原因)。 请尝试在引用的要点中打开网络文件,如果使用工具看到具有相同尺寸的权重,请检查。 You are rig ...
  • 在这种情况下, 卷积神经网络不是最佳选择。 顺便说一句,你可以用Conv1d轻松完成这件事: model = keras.Sequential() model.add(keras.layers.Embedding(44, 100)) model.add(keras.layers.Conv1D(50, kernel_size=1, strides=1)) model.add(keras.layers.GlobalAveragePooling1D()) # model.add(keras.layers.Dens ...
  • 这似乎是一个非常简单的问题。 数据内部的结构非常少,所以我认为你可以尝试通过去除最后两个卷积和最大汇集层来减少神经网络的深度。 而是增加完全连接层中的节点数量,如下所示: model = Sequential() model.add(Conv2D(32, 3, activation='relu', input_shape=[100, 100, 1])) model.add(MaxPool2D()) model.add(BatchNormalization()) model.add(Conv2D(64, 3 ...
  • 错误是因为你的模型定义,而不是ImageDataGenerator (我没有看到你已经发布的代码中使用)。 我假设len(classes) = 2因为你得到的错误信息。 由于模型的最后一层期望trainingLabels对每个数据点都有一个大小为2的矢量,但您的trainingLabels标签是一维数组,因此您会收到错误。 为了解决这个问题,你可以改变你的最后一层只有1个单元,因为它是二进制分类: model.add(Dense(1)) 或者您可以使用一种热门编码将您的训练和验证标签更改为矢量: from ...
  • 不,它们可以是不同的名称,它取决于您如何加载数据。 在你的情况下,你可以使用flow_from_directory来生成训练数据,实际上目录将是关联的类,这是ImageDataGenerator的一部分。 No they can be of different names, it really depends on how you load your data. In your case, you can use flow_from_directory to generate the training da ...
  • 我想这是你想要实现的架构的一部分: | RELU | -- > | RELU | --> | RELU | --> | RELU | | | | | | | | | ----------------> | RELU | <----------------- 假设你有一 ...
  • 您可以使用summary函数找出Keras模型中(非)可训练参数的数量: from keras import models, layers model = models.Sequential() model.add(layers.Conv2D(10, (4,4), input_shape=(32, 32, 3))) model.summary() 这是输出: Layer (type) Output Shape Param # ====== ...
  • 为什么scikit-learn功能不能完成这项工作? 您将所有样本(图像)转发到列车/测试集中,将单热编码转换为标签编码(请参阅链接 ),并将其作为y_pred传递到y_pred 。 你以y_true (单热标签)以类似的方式继续。 示例代码: import sklearn.metrics as metrics y_pred_ohe = KerasClassifier.predict(X) # shape=(n_samples, 12) y_pred_labels = np.argmax(y_pred_ ...
  • 问题是由输出类的数量(三)与您选择的最终层激活(Sigmoid)和损失函数(二进制交叉熵)之间的不匹配引起的。 sigmoid函数将实际值“压缩”为[0,1]之间的值,但它仅针对二进制(两类)问题而设计。 对于多个类,您需要使用softmax函数之类的东西。 Softmax是sigmoid的一般化版本(当你有两个类时,这两个应该是等价的)。 损失值也需要更新为可以处理多个类的损失值 - 在这种情况下,分类交叉熵将起作用。 在代码方面,如果您将模型定义和编译代码修改为下面的版本,它应该可以工作。 model ...
  • 如果您的数据在空间上是相关的(您说它不是),那么您可以将其提供给形状为1xNx1或Nx1x1(行xcs x通道)的convnet(或者,特别是conv2d层)。 如果这根本不是空间数据 - 你只有N个非空间相关的特征,那么形状应该是1x1xN。 为了完整起见,我应该指出,如果你的数据确实是非空间的,那么使用卷积层/网络真的没有意义。 您可以将其塑造为1x1xN,然后使用1x1卷积,但由于1x1卷积与完全连接(也称为密集又称线性)层完全相同,因此您可能只需使用它。 If your data were spat ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)