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

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

我在使用 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]