gpt4 book ai didi

javascript - 错误 : The shape of dict ['input' ] provided in model.execute(dict) 必须是 [1,224,224,3],但实际上是 [1,244,244,3]

转载 作者:行者123 更新时间:2023-12-03 01:30:40 26 4
gpt4 key购买 nike

我在使用tensorflow.js时遇到一个奇怪的错误:

Error: The shape of dict['input'] provided in model.execute(dict) must be [1,224,224,3], but was [1,244,244,3]

所以尺寸是相同的......但不知何故它是不正确的。任何帮助将不胜感激。

我的代码如下:

import React, { Component } from "react";
import "./App.css";
import * as tf from "@tensorflow/tfjs";
import { loadFrozenModel } from "@tensorflow/tfjs-converter";
class App extends Component {
// Set state
state = { selectedFile: null, input: null };
// File selected
fileChangedHandler = event => {
this.setState({ selectedFile: event.target.files[0] });
};
// File uploaded
uploadHandler = () => {
// Read file
let reader = new FileReader();
reader.addEventListener("loadend", () => {
// Set width and height of image
let img = new Image(244, 244);
img.src = reader.result;
// Convert to tensor
let imgTensor = tf.fromPixels(img);
// Init input with correct shape
let input = tf.zeros([1, 244, 244, 3]);
// Add img to input
input[0] = imgTensor;
this.setState({ input });
});
// Get img URL
reader.readAsDataURL(this.state.selectedFile);
};

componentDidMount() {
// Load model
loadFrozenModel(
"http://.../tf_models/tensorflowjs_model.pb",
"http://.../tf_models/weights_manifest.json"
).then(model => this.setState({ model }));
}

componentDidUpdate() {
// Image and model are ready
if (this.state.model && this.state.input) {
// Use model for prediction
this.state.model.execute({
input: this.state.input
}).print();
}
}
render() {
return (
<div className="App">
<input type="file" onChange={this.fileChangedHandler.bind(this)} />
<button onClick={this.uploadHandler.bind(this)}>Upload!</button>
</div>
);
}
}

export default App;

最佳答案

错误中的值不同:

Error: The shape of dict['input'] provided in model.execute(dict) must be [1,224,224,3], but was [1,244,244,3]

关于javascript - 错误 : The shape of dict ['input' ] provided in model.execute(dict) 必须是 [1,224,224,3],但实际上是 [1,244,244,3],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51325969/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com