小编mat*_*ang的帖子

ValueError:输入 0 与 keras 中的层密集_6 不兼容

我正在尝试按照此链接构建深度自动编码器,但出现此错误:

值错误:输入 0 与层密集_6 不兼容:输入形状的预期轴 -1 具有值 128 但得到形状(无,32)

编码:

input_img = Input(shape=(784,))
encoded = Dense(128, activation='relu')(input_img)
encoded = Dense(64, activation='relu')(encoded)
encoded = Dense(32, activation='relu')(encoded)

decoded = Dense(64, activation='relu')(encoded)
decoded = Dense(128, activation='relu')(decoded) #decode.shape = (?,128)
decoded = Dense(784, activation='relu')(decoded)

autoencoder = Model(input_img, decoded)

encoder = Model(input_img, encoded)
encoded_input = Input(shape=(encoding_dim,))
decoder_layer = autoencoder.layers[-1]
decoder = Model(encoded_input, decoder_layer(encoded_input)) #ERROR HERE
...
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误:

Traceback (most recent call last):
  File "autoencoder_deep.py", line 37, in <module>
    decoder = Model(encoded_input, decoder_layer(encoded_input))
  File …
Run Code Online (Sandbox Code Playgroud)

neural-network keras keras-layer

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

有没有一种方法可以跳过Angular中的单元测试套件?

到目前为止,我有一些不应运行的单元测试,是否可以跳过它们?除了在要运行的程序上使用fdescribe之外。

angular angular6

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

更改焦点时不会读出辅助功能提示

当我以编程方式将画外音焦点移至标签时,不会读出标签的提示。我该如何解决这个问题?仅读出可访问性标签。

UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, self.label)

uiaccessibility swift

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

iOS 旁白“未找到标题”

我有一个 UITableView,其中每个 UITableViewCell 有 2 个 UILabels:1 个标题和 1 个内容。标头的 AccessibilityTrait 设置为“标头”。使用 Accessibility Inspector 检查模拟器屏幕时,我能够正确地看到特征集。但是在实际设备上,当我将转子切换到“标题”时,它只找到导航栏标题,而在 UITableViewCells 中找不到标题。

accessibility ios voiceover

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

如何选择每个卷积层中的过滤器数量?

在构建卷积神经网络时,如何确定每个卷积层使用的滤波器数量。我知道过滤器的数量没有硬性规定,但是根据您阅读的经验/论文等,是否有关于使用的过滤器数量的直觉/观察?

例如(我只是将其作为示例):

  • 随着网络的深入,使用更多/更少的过滤器。

  • 使用大/小内核大小的大/小过滤器

  • 如果图像中感兴趣的对象是大/小,请使用 ...

neural-network deep-learning conv-neural-network keras

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

如何找出nodejs版本支持哪种版本的angular-cli?

我正在使用nodejs v8.8.1和angular-cli v6.0.8,我收到了这个错误:

您正在运行Node.js的v8.8.1版本,Angular CLI v6不支持该版本.支持的官方Node.js版本是8.9或更高版本.

如果我要安装不同版本的angular-cli,我该如何检查nodejs v8.8.1支持哪个版本?因为我必须使用nodejs v8.8.1,所以我无法做到这一点.

node.js npm node-modules angular-cli angular

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

动态创建formGroup时,control.setParent不是函数

我正在使用Angular5,并且有一个字段列表,每个字段都有一个名称和FormControl。我尝试使用此代码将控件动态添加到组中,但出现错误。

const formControlFields = [
  {name: 'field1',control: [null, []] as FormControl},
  {name: 'field2',control: [null, []] as FormControl}
];

const formGroup: FormGroup = new FormGroup({});
formControlFields.forEach( f =>  formGroup.addControl(f.name,f.control));
this.form = new FormGroup({groups:formGroup});
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误:

错误TypeError:control.setParent不是函数

at FormGroup.registerControl (forms.js:4352)
at FormGroup.addControl (forms.js:4372)
at eval (trade-search.component.ts:142)
Run Code Online (Sandbox Code Playgroud)

angular angular-forms angular-formbuilder

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

ValueError:张量“ A”必须与张量“ B”来自同一图

我正在使用keras的预训练模型,调用ResNet50(weights ='imagenet')时出现错误。我在Flask服务器中有以下代码:

def getVGG16Prediction(img_path):

    model = VGG16(weights='imagenet', include_top=True)
    img = image.load_img(img_path, target_size=(224, 224))
    x = image.img_to_array(img)
    x = np.expand_dims(x, axis=0)
    x = preprocess_input(x)

    pred = model.predict(x)
    return sort(decode_predictions(pred, top=3)[0])


def getResNet50Prediction(img_path):

    model = ResNet50(weights='imagenet') #ERROR HERE
    img = image.load_img(img_path, target_size=(224, 224))
    x = image.img_to_array(img)
    x = np.expand_dims(x, axis=0)
    x = preprocess_input(x)

    preds = model.predict(x)
    return decode_predictions(preds, top=3)[0]
Run Code Online (Sandbox Code Playgroud)

main中调用时,它工作正常

if __name__ == "__main__":
    STATIC_PATH = os.getcwd()+"/static"
    print(getVGG16Prediction(STATIC_PATH+"/18.jpg"))
    print(getResNet50Prediction(STATIC_PATH+"/18.jpg"))
Run Code Online (Sandbox Code Playgroud)

但是,当我从烧瓶POST函数调用它时,ValueError上升:

@app.route("/uploadMultipleImages", methods=["POST"])
def uploadMultipleImages():
    uploaded_files = request.files.getlist("file[]")
    weight = request.form.get("weight") …
Run Code Online (Sandbox Code Playgroud)

neural-network flask keras tensorflow

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

如何创建颜色和标记的图例?

我想在图例中同时显示颜色和标记。颜色代表一件事,标记代表另一件事。它看起来应该像附加的图像。这是我目前的代码:

x = np.arange(20)
y = np.sin(x)

fig, ax = plt.subplots()
line1 = ax.scatter(x[:10],y[:10],20, c="red", picker=True, marker='*')
line2 = ax.scatter(x[10:20],y[10:20],20, c="red", picker=True, marker='^')

ia = lambda i: plt.annotate("Annotate {}".format(i), (x[i],y[i]), visible=False)
img_annotations = [ia(i) for i in range(len(x))] 

def show_ROI(event):
    for annot, line in zip([img_annotations[:10],img_annotations[10:20]], [line1, line2]):
        if line.contains(event)[0]:
            ...
    fig.canvas.draw_idle()

fig.canvas.mpl_connect('button_press_event', show_ROI)

plt.show()
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

python matplotlib legend

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

Keras 在训练时不显示进度条箭头

起初,我在 tensorflow 后端运行 keras,并且进度条很好。然后我安装了 Theano,并在切换回 tensorflow 之前尝试使用它一段时间。安装 Theano 后,出现在每个 epoch 的进度条只会在 epoch 完成后出现,所以在训练时,我看不到它的进度。

Epoch 1/50
21/21 [=============================] 10s - loss:0.6928 - loss_val: 0.6912
Run Code Online (Sandbox Code Playgroud)

我希望它在训练时显示进度,如下所示:

Epoch 1/50
21/21 [=====>.......................] 10s - loss:0.6928 - loss_val: 0.6912
Run Code Online (Sandbox Code Playgroud)

为什么安装theano后进度条格式变了,怎么改成显示进度?

theano keras tensorflow

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

如何将数组值 0 和 255 转换为对应的 0 和 1 数组

我有一个表示为 numpy 数组的图像,其值为 0 和 255(范围内没有其他值)。将其转换为 0 和 1 数组的最佳方法是什么。

python numpy

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

如何导入 Angular Material Css

我正在尝试在我的项目中使用 Angular Material 并且导入了标签,但并非所有样式都在那里。

在我的 HTML 中:

<mat-form-field>
  <input matInput [matDatepicker]="picker" placeholder="Choose a date">
  <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
  <mat-datepicker #picker startView="year" [startAt]="startDate"></mat-datepicker>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)

它应该显示:

在此处输入图片说明

但它显示:

在此处输入图片说明

我添加@import "~@angular/material/prebuilt-themes/indigo-pink.css";到 style.css 并且日历显示正常,但文本字段看起来仍然很糟糕。

在此处输入图片说明

angular-material angular-material2 angular-material-5

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

Scikit-learn ValueError:使用混淆矩阵时不支持未知

我使用 fusion_matrix 模块来可视化类预测结果与实际值的比较。

val= ... #shape (3000,1,30) dtype float32
pred = ... #shape (3000,1,30) dtype float32

cnf_matrix = confusion_matrix(val, pred) #ERROR HERE
Run Code Online (Sandbox Code Playgroud)

我收到这个错误:

回溯(最近一次调用最后一次):文件“vis.py”,第 757 行,在 cnf_matrix = fusion_matrix(y_test, y_pred) 文件“C:\Anaconda\envs\nn35\lib\site-packages\sklearn\metrics\classification. py”,第 240 行,confusion_matrix y_type, y_true, y_pred = _check_targets(y_true, y_pred) 文件“C:\Anaconda\envs\nn35\lib\site-packages\sklearn\metrics\classification.py”,第 89 行,在_check_targets raise ValueError("不支持{0}".format(y_type)) ValueError: 不支持未知

我做错了什么?

scikit-learn

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