小编Jür*_* K.的帖子

获取keras中所有已知类别的vgg-16的列表

我使用Keras预训练的VGG-16型号.

到目前为止我的工作源代码是这样的:

from keras.applications.vgg16 import VGG16
from keras.preprocessing.image import load_img
from keras.preprocessing.image import img_to_array
from keras.applications.vgg16 import preprocess_input
from keras.applications.vgg16 import decode_predictions

model = VGG16()

print(model.summary())

image = load_img('./pictures/door.jpg', target_size=(224, 224))
image = img_to_array(image)  #output Numpy-array

image = image.reshape((1, image.shape[0], image.shape[1], image.shape[2]))

image = preprocess_input(image)
yhat = model.predict(image)

label = decode_predictions(yhat)
label = label[0][0]

print('%s (%.2f%%)' % (label[1], label[2]*100))
Run Code Online (Sandbox Code Playgroud)

我宣布该模型已经训练了1000个班级.有没有可能得到这个模型训练的类列表?打印出所有预测标签不是一种选择,因为只返回了5个.

提前致谢

python classification deep-learning keras vgg-net

6
推荐指数
1
解决办法
6065
查看次数

URI路径不是绝对异常java(不是android)

我有以下一段源代码

import java.net.URI;
import java.net.URISyntaxException;

    File file = new File("pic.png");
    BufferedImage image = ImageIO.read(file);
    String string = "pic.png";
 //the code works fine until here
    URI path = new URI(string);
    File f = new File(path);
    ColorProcessor image = new ColorProcessor(ImageIO.read(f));
Run Code Online (Sandbox Code Playgroud)

所以File获取的路径是正确的.图像也正确缓冲.现在我的问题是我得到以下异常

Exception in thread "main" java.lang.IllegalArgumentException: URI is not absolute
    at java.io.File.<init>(Unknown Source)
Run Code Online (Sandbox Code Playgroud)

为什么我的道路不是绝对的?我该怎么做呢?

如果我改变这样的路径:

String string = "C:'\'Users'\'Jurgen'\'newFile'\'myProject'\'pic.png";
Run Code Online (Sandbox Code Playgroud)

也试过这样的

String string = "C:/Users/Jurgen/newFile/myProject/pic.png";
Run Code Online (Sandbox Code Playgroud)

然后我得到一个新的例外

Exception in thread "main" java.lang.IllegalArgumentException: URI is not hierarchical
    at java.io.File.<init>(Unknown Source)
Run Code Online (Sandbox Code Playgroud)

PS没有使用uri的android包

在此先感谢=)

java uri exception file path

5
推荐指数
1
解决办法
1万
查看次数

BLEU分数的变化

我对机器翻译的蓝分计算有一些疑问.我意识到他们可能有不同的BLEU指标.我发现代码报告了BLEU的五个值,即BLEU-1,BLEU-2,BLEU-3,BLEU-4以及最后的BLEU,它们似乎是前四个BLEU的指数平均值.我还不清楚它们之间的区别是什么.你有什么想法?谢谢

Ps起初我认为这个问题更多的是理论内容,并将其发布在meta stackexange上.主持人已关闭并将其评论为stackoverflow类型问题.所以请不要再惩罚我.=)

evaluation metrics translation machine-learning bleu

5
推荐指数
2
解决办法
2204
查看次数

ValueError:builtins.type的大小错误,请尝试重新编译

我有给定的Python代码,我在PyCharm的venv中使用它.

from keras.applications.resnet50 import ResNet50
from keras.preprocessing import image
from keras.applications.resnet50 import preprocess_input, decode_predictions
import numpy as np
print (np.__version__)
Run Code Online (Sandbox Code Playgroud)

代码抛出以下异常:

  File "type.pxd", line 9, in init mtrand
ValueError: builtins.type has the wrong size, try recompiling. Expected 840, got 864
PyDev console: starting.
Python 3.5.0a4 (v3.5.0a4:413e0e0004f4, Apr 19 2015, 18:01:47) [MSC v.1900 64 bit (AMD64)] on win32
Run Code Online (Sandbox Code Playgroud)

我已经看过这个类似的主题, 我在描述中升级了所有内容:

pip install --upgrade numpy
pip install --upgrade scipy
pip install --upgrade pandas
Run Code Online (Sandbox Code Playgroud)

此外还有特定的熊猫版本.

pip install pandas==0.13.1
Run Code Online (Sandbox Code Playgroud)

我仍然得到同样的例外.你还有其他建议吗?提前致谢

python error-handling numpy pycharm pandas

5
推荐指数
0
解决办法
125
查看次数

为什么我会收到错误:在R类中找不到符号变量

以下源代码应制作图片并在屏幕上显示.但我得到一些错误.Cannot resolve symbol 'activity_fullscreen',同样为imageView1,dummy_button,fullscreen_contentfullscreen_content_controls.

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fullscreen);

        mVisible = true;
        mControlsView = findViewById(R.id.fullscreen_content_controls);
        mContentView = findViewById(R.id.fullscreen_content);


        // Set up the user interaction to manually show or hide the system UI.
        mContentView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                toggle();
            }
        });

        // Upon interacting with UI controls, delay any scheduled hide()
        // operations to prevent the jarring behavior of controls going away
        // while interacting …
Run Code Online (Sandbox Code Playgroud)

java android r.java-file cannot-find-symbol

4
推荐指数
1
解决办法
8550
查看次数

在java中对元组列表进行排序的有效方法

给定的通用数据类型看起来像这样:HashMap<EdgeTuple, Double> edgeList其中元组是一个类EdgeTuple而Double是一个对任务不重要的权重:

class EdgeTuple{
    int label1;
    int label2;
    public EdgeTuple(int label1, int label2){
        int min = Math.min(label1, label2);
        int max = Math.max(label1, label2);
        this.label1 = min;
        this.label2 = max;
    }
}
Run Code Online (Sandbox Code Playgroud)

因此,您可以看到元组已经在第一个位置上具有较小的值.我想要做的是对最终输入顺序应该如下所示的列表进行排序:

条目0:[(0,某事物); some_weight]

第1项:[(1,某事); some_weight]

...

条目n-1:[(last_value,something); some_weight]

所以基本上我需要做的是对元组的第一个值进行升序排序.我对这个主题的红色最喜欢的现有答案,但仍然找不到令人满意的东西.

一种可能的解决方案是依靠比较器,如下所示:

Comparator<Tuple> myComparator = new Comparator<Tuple>() {
    public int compare(Tuple t1, Tuple t2) {
        //the comparison rules go here
    }
};
Collections.sort(tupleList, myComparator);
Run Code Online (Sandbox Code Playgroud)

每对元组的比较似乎并不安静.所以我的问题是,您是否知道其他任何排序方式?也许一些新的数据类型为给定的任务提供了一个合适的更高性能的接口?

谢谢

java sorting performance tuples list

3
推荐指数
1
解决办法
2401
查看次数

ConfusionMatrixDisplay (Scikit-Learn) 绘图标签超出范围

以下代码绘制了一个混淆矩阵:

from sklearn.metrics import ConfusionMatrixDisplay

confusion_matrix = confusion_matrix(y_true, y_pred)
target_names = ["aaaaa", "bbbbbb", "ccccccc", "dddddddd", "eeeeeeeeee", "ffffffff", "ggggggggg"]
disp = ConfusionMatrixDisplay(confusion_matrix=confusion_matrix, display_labels=target_names)
disp.plot(cmap=plt.cm.Blues, xticks_rotation=45)
plt.savefig("conf.png")
Run Code Online (Sandbox Code Playgroud)

混淆矩阵

这个情节有两个问题。

  1. y 轴标签被切断(真实标签)。x 标签也被切断。
  2. 对于 x 轴来说,名称太长。

为了解决第一个问题,我尝试使用poof(bbox_inches='tight')它,不幸的是 sklearn 不可用。在第二种情况下,我尝试了以下2.解决方案,这导致了完全扭曲的情节。

总而言之,我正在为这两个问题而苦苦挣扎。

python plot confusion-matrix scikit-learn

2
推荐指数
1
解决办法
4811
查看次数

Bash 脚本语法错误:预期操作数(错误标记为“=”)

我需要做的是将一个长文本文件以相同的行数切割成 10 个和平区。因此我编写了以下脚本。

#!/usr/bin/bash
filename="$1"
count=0
file=0
br=$(wc -l $filename | awk '{print $1}')
let br = $br/10
while read -r line
do
let count = count + 1
    name="$line"
echo $name >> file$file.csv
if [ $count = $br ];then
let count=0
let file+=1
fi
done < "$filename"
Run Code Online (Sandbox Code Playgroud)

脚本产生以下错误,我不明白

cut.sh: line 9: let: =: syntax error: operand expected (error token is "=")
Run Code Online (Sandbox Code Playgroud)

我已经阅读了类似的主题,但仍然找不到解决方案。欢迎任何想法。谢谢

syntax bash

1
推荐指数
1
解决办法
9044
查看次数

从字典中删除索引

给定的是在长度为n的列表中具有未排序索引的列表。列表的每个元素仅包含一次。所以列表看起来像这样

L = [13, 145, 70001, 34, ..., 533]
Run Code Online (Sandbox Code Playgroud)

还给出了以dictionary d哪个数值作为键。所有值都是element {0,1}。喜欢

d = {
        "[some data]" : 0,
        "[some data]" : 1,
        "[some data]" : 1,
        "[some data]" : 1,
        ...
        "[some data]" : 0
    }
Run Code Online (Sandbox Code Playgroud)

字典d中的条目比列表中的要多L

我想做的是从字典中删除每个位置(索引)的数据(L如果是的话)0

我在进行此操作时看到的问题是,每次删除后索引都需要移动,因为字典中的位置正在更改。关于大量项目,这是安静的低效L。必须有一种有效的方法来执行此任务。

任何想法和建议都将受到高度赞赏!

python indexing dictionary list processing-efficiency

1
推荐指数
1
解决办法
63
查看次数