- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
谁能向我解释一下这里发生了什么?
这是我的代码:
var model;
async function deploy() {
console.log('Deploying model...');
model = await tf.loadLayersModel('keras model/js_model/model.json');
console.log('model loaded!');
var sample_image = document.getElementById('test_image');
sample_image = tf.browser.fromPixels(sample_image);
var sample_image_height = sample_image.shape[0];
var sample_image_width = sample_image.shape[1];
sample_image.reshape([-1, sample_image_height, sample_image_width, 3]);
result = await model.predict(sample_image);
console.log(result);
}
deploy();
它会产生错误消息:
Uncaught (in promise) Error: Error when checking : expected conv2d_13_input to have 4 dimension(s), but got array with shape [100,120,3]
这是 model.json 中的 conv2d_13 batch_input_shape 属性:
"batch_input_shape": [null, 250, 250, 3]
我想知道出了什么问题...
编辑:这是我的模型摘要:
Model: "sequential_1"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv2d_1 (Conv2D) (None, 248, 248, 32) 896
_________________________________________________________________
batch_normalization_1 (Batch (None, 248, 248, 32) 128
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 124, 124, 32) 0
_________________________________________________________________
conv2d_2 (Conv2D) (None, 122, 122, 64) 18496
_________________________________________________________________
batch_normalization_2 (Batch (None, 122, 122, 64) 256
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 61, 61, 64) 0
_________________________________________________________________
conv2d_3 (Conv2D) (None, 59, 59, 64) 36928
_________________________________________________________________
batch_normalization_3 (Batch (None, 59, 59, 64) 256
_________________________________________________________________
max_pooling2d_3 (MaxPooling2 (None, 29, 29, 64) 0
_________________________________________________________________
conv2d_4 (Conv2D) (None, 27, 27, 64) 36928
_________________________________________________________________
batch_normalization_4 (Batch (None, 27, 27, 64) 256
_________________________________________________________________
max_pooling2d_4 (MaxPooling2 (None, 13, 13, 64) 0
_________________________________________________________________
conv2d_5 (Conv2D) (None, 11, 11, 64) 36928
_________________________________________________________________
batch_normalization_5 (Batch (None, 11, 11, 64) 256
_________________________________________________________________
max_pooling2d_5 (MaxPooling2 (None, 5, 5, 64) 0
_________________________________________________________________
conv2d_6 (Conv2D) (None, 3, 3, 64) 36928
_________________________________________________________________
batch_normalization_6 (Batch (None, 3, 3, 64) 256
_________________________________________________________________
max_pooling2d_6 (MaxPooling2 (None, 1, 1, 64) 0
_________________________________________________________________
flatten_1 (Flatten) (None, 64) 0
_________________________________________________________________
dense_1 (Dense) (None, 512) 33280
_________________________________________________________________
dense_2 (Dense) (None, 512) 262656
_________________________________________________________________
dropout_1 (Dropout) (None, 512) 0
_________________________________________________________________
dense_3 (Dense) (None, 2) 1026
=================================================================
Total params: 465,474
Trainable params: 464,770
Non-trainable params: 704
_________________________________________________________________
最佳答案
sample_image.reshape([-1, sample_image_height, sample_image_width, 3]);
reshape
不是就地运算符。您需要将结果分配回变量sample_image
或使用另一个变量
const sample_image_reshaped = sample_image.reshape([-1, sample_image_height, sample_image_width, 3]);
model.predict(sample_image_reshaped)
关于python - Tensorflow js : Error: Error when checking : expected conv2d_13_input to have 4 dimension(s), 但得到形状为 [100,120,3] 的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59374748/
我正在尝试从以下路径中提取一组关键字,例如 ['lemon', 'apple', 'coconut'] 等"\var\prj\lemon_123\xyz","\var\prj\123_apple\co
每次当我尝试连接到发送 servage smpt 时,它都会给我一个错误: SMTP connect() failed. 我尝试以下设置: include('res/mailer/class.phpm
我正在尝试通过 cpanel cron 作业面板提交 MySQL 备份脚本,但我收到了我不理解的错误。我已经在我的 Ubuntu 上尝试了这个命令 mysqldump -u(USERNAME) -p(
我喜欢将测试程序的输出记录到带有时间戳的日志文件中。 我创建了以下 Makefile,但它不起作用。 “make”似乎在最后一刻根据需要计算 LOGFILE。 生成文件 LOGFILE=`date +
我是一名优秀的程序员,十分优秀!