gpt4 book ai didi

json - TensorflowJS : Failed to parse model. json

转载 作者:行者123 更新时间:2023-12-03 21:00:36 25 4
gpt4 key购买 nike

我已经重新训练并将 Mobilenet 模型转换为 model.json 文件。此文件已加载到我的图像分类平台(获得 200 OK 状态代码),但未被识别为正确的 json。

我已经使用这些站点来验证我的 json 文件

https://jsonlint.com/

https://jsonformatter.curiousconcept.com/

并且都将我的文件作为经过验证的 json 返回。

其他两个 JSON 文件以相同的方式加载到页面中,并且它们没有返回错误

但是我仍然不断收到此错误:
Uncaught (in promise) Error: Failed to parse model JSON of response from https://localhost/pathto/model.json. Please make sure the server is serving valid JSON for this request.
有谁知道文件可能有什么问题?

编辑:
我没有以任何方式触及 model.json,我只是将它加载到我的 index.js 文件中并得到了错误。

这也是我的 index.js(完整版):

  const MODEL_URL =
"https://localhost/tfjs_models/model.json";
const WEIGHTS_URL =
"https://localhost/tfjs_models/weights_manifest.json";
let model;
let IMAGENET_CLASSES = [];
let offset = tf.scalar(128);
async function loadModelAndClasses() {
$.getJSON(
"https://localhost/tfjs_models/labels.json",
function(data) {
$.each(data, function(key, val) {
IMAGENET_CLASSES.push(val);
});
}
);
model = await tf.loadGraphModel(MODEL_URL, WEIGHTS_URL);
//console.log("After model is loaded: " + tf.memory().numTensors);
$(".loadingDiv").hide();
$("#inputImage").attr("disabled", false);
}
loadModelAndClasses();
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();

reader.onload = function(e) {
$("#imageSrc")
.attr("src", e.target.result)
.width(224)
.height(224);
};

reader.readAsDataURL(input.files[0]);
//console.log("After image is loaded: " + tf.memory().numTensors);

reader.onloadend = async function() {
console.log("Before predictions: " + tf.memory().numTensors);

let imageData = document.getElementById("imageSrc");

//console.log("After offset: " + tf.memory().numTensors);
let pixels1 = tf.fromPixels(imageData);
let pixel2 = pixels1.resizeNearestNeighbor([224, 224]);
let pixel3 = pixel2.toFloat();
console.log("After pixels are formed: " + tf.memory().numTensors);

let pixels = pixel3.sub(offset);
let pixels4 = pixels.div(offset);
let pixels5 = pixels4.expandDims();
console.log("After pre-processing: " + tf.memory().numTensors);

const output = await model.predict(pixels5);
console.log("After output: " + tf.memory().numTensors);
const predictions = Array.from(output.dataSync())
.map(function(p, i) {
return {
probabilty: p,
classname: IMAGENET_CLASSES[i]
};
})
.sort((a, b) => b.probabilty - a.probabilty)
.slice(0, 10);

//console.log(predictions);
var html = "";
for (let i = 0; i < 10; i++) {
html += "<li>" + predictions[i].classname + "</li>";
}
$(".predictionList").html(html);
console.log("After predictions: " + tf.memory().numTensors);

pixels.dispose();
pixels1.dispose();
pixel2.dispose();
pixel3.dispose();
pixels4.dispose();
pixels5.dispose();
output.dispose();
console.log("After dispose: " + tf.memory().numTensors);
};
}
}

这是模型的链接,因为它是由 TensorflowJS Converter 生成的。

https://github.com/dvbeelen/tfjs_model

最佳答案

模型加载错误。这是doc

这应该足以加载模型

model = await tf.loadGraphModel(MODEL_URL)
weights_manifest.json不需要提供

关于json - TensorflowJS : Failed to parse model. json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58100305/

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