[未处理的承诺拒绝:TypeError:未定义不是对象(正在评估'clarifai.GENERAL.MODEL')]

时间:2019-11-10 05:57:39

标签: react-native clarifai

enter image description here

我捕获图像时显示此错误,并且clarifai没有提供任何结果,也没有任何预测答案。是显示错误“ [未处理的承诺拒绝:TypeError:未定义不是对象(正在评估'clarifai.GENERAL.MODEL')”]“。谢谢,请帮我。

const Clarifai = require('clarifai');

const clarifai = new Clarifai.App({
  apiKey: '851f7efad90241fc807252f3da705d6d'
});
process.nextTick = setImmediate;

state = {
    hasCameraPermission: null,
    predictions: [],
  };

async componentWillMount() {
    const { status } = await Permissions.askAsync(Permissions.CAMERA);
    this.setState({ hasCameraPermission: status === 'granted' });
  }

capturePhoto = async () => {
    if (this.camera) {
      var photo = await this.camera.takePictureAsync();
      return photo.uri;
    }
  };

resize = async photo => {
    let manipulatedImage = await ImageManipulator.manipulateAsync(
      photo,
      [{ resize: { height: 300, width: 300 } }],
      { base64: true }
    );
    return manipulatedImage.base64;
  };

predict = async image => {
    let predictions = await clarifai.models.predict(
      clarifai.GENERAL.MODEL, // model need to get prediction from
      image
    );
    return predictions;
  };

objectDetection = async () => {
    let photo = await this.capturePhoto();
    let resized = await this.resize(photo);
    let predictions = await this.predict(resized);
    this.setState({ predictions: predictions.outputs[0].data.concepts });
    console.log(this.state.predictions)
  };

1 个答案:

答案 0 :(得分:1)

您应该改用它。

 clarifai.GENERAL.MODEL  ==> clarifai.GENERAL_MODEL