未捕获的DOMException:无法在'IDBObjectStore'上执行'delete':事务未激活

问题描述 投票:0回答:1

当我尝试将我的tensorflowjs模型保存在IndexedDb中时,出现此错误。基本上,我正在开发一个可以实时预测情绪的离线Web应用程序。为了使我的应用程序更快,我必须使用索引Db。前端在Reactjs中。该行出现错误:

await this.model.save('indexeddb://' + INDEXEDDB_KEY);

这里是代码。

  try {
    this.model = await tf.loadLayersModel('indexeddb://' + INDEXEDDB_KEY);

    // Safe to assume tensorflowjs database and related object store exists.
    // Get the date when the model was saved.
    try {
      const db = await openDB(INDEXEDDB_DB, 1, );
      const item = await db.transaction(INDEXEDDB_STORE)
                           .objectStore(INDEXEDDB_STORE)
                           .get(INDEXEDDB_KEY);
      const dateSaved = new Date(item.modelArtifactsInfo.dateSaved);
      await this.getModelInfo();
      console.log(this.modelLastUpdated);
      if (!this.modelLastUpdated  || dateSaved >= new Date(this.modelLastUpdated).getTime()) {
        console.log('Using saved model');
      }
      else {
        this.setState({
          modelUpdateAvailable: true,
          showModelUpdateAlert: true,
        });
      }

    }
    catch (error) {
      console.warn(error);
      console.warn('Could not retrieve when model was saved.');
    }

  }
  // If error here, assume that the object store doesn't exist and the model currently isn't
  // saved in IndexedDB.
  catch (error) {
    console.log('Not found in IndexedDB. Loading and saving...');
    console.log(error);

    this.model = await tf.loadLayersModel(MODEL_PATH);
    console.log(this.model,"model")
    await this.model.save('indexeddb://' + INDEXEDDB_KEY);
  }
}
// If no IndexedDB, then just download like normal.
else {
  console.warn('IndexedDB not supported.');
  this.model = await tf.loadLayersModel(MODEL_PATH);
}

this.setState({ modelLoaded: true });


// Warm up model.
// let prediction = tf.tidy(() => this.model.predict(tf.zeros([1, IMAGE_SIZE, IMAGE_SIZE, 3])));
// prediction.dispose();

}

'''

reactjs indexeddb tensorflow.js
1个回答
0
投票

如果没有待处理的请求,事务将关闭。看起来您的等待对象正在做一些非indexeddb的事情,所以自然地,因为您没有立即在事务上排队一些请求,所以它关闭了,然后当您最终在事务上稍后请求某项时,它被关闭了时间(无效)。

在执行其他异步操作后开始交易。在开始事务和向它添加请求之间不要做异步的事情。

© www.soinside.com 2019 - 2024. All rights reserved.