Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript tensorflowjs加载重新训练的coco ssd模型-在浏览器中不工作_Javascript_Python 3.x_Tensorflow_Tensorflowjs Converter - Fatal编程技术网

Javascript tensorflowjs加载重新训练的coco ssd模型-在浏览器中不工作

Javascript tensorflowjs加载重新训练的coco ssd模型-在浏览器中不工作,javascript,python-3.x,tensorflow,tensorflowjs-converter,Javascript,Python 3.x,Tensorflow,Tensorflowjs Converter,我使用Python模型/研究/对象检测API用我自己的数据集重新训练coco ssd。 我已经保存了模型&模型在ipython笔记本中工作。 我使用tfjs_转换器来转换它 tensorflowjs_转换器--输入格式=tf_保存的_模型--输出格式=tensorflowjs--输出节点名称=“检测”框、检测类、检测分数、数量检测”-保存的_模型标签=服务/保存的_模型/web模型 试验1;我的代码 image.src = imageURL; var img; const

我使用Python模型/研究/对象检测API用我自己的数据集重新训练coco ssd。 我已经保存了模型&模型在ipython笔记本中工作。 我使用tfjs_转换器来转换它 tensorflowjs_转换器--输入格式=tf_保存的_模型--输出格式=tensorflowjs--输出节点名称=“检测”框、检测类、检测分数、数量检测”-保存的_模型标签=服务/保存的_模型/web模型

试验1;我的代码

    image.src = imageURL;
    var img;
    const runButton = document.getElementById('run');
    runButton.onclick = async () => {
        console.log('model start');
        const model = await modelPromise;

        console.log('model loaded');
        const zeros = tf.zeros([1, 224, 224, 3]);

        const batched = tf.tidy(() => {
        if (!(image instanceof tf.Tensor)) {
            img = tf.fromPixels(image);
         }
      // Reshape to a single-element batch so we can pass it to executeAsync.
          return img.expandDims(0);
       });
       console.log('model loaded - now predict .. start');
       const result = await model.executeAsync(batched) ;
       console.log('model loaded - now predict - ready'); //  Error seen 
       batched.dispose();
       tf.dispose(result);

    model loaded - now predict .. start ( i tried chaning the model to Coco-ssd model same error)
   tensor_array.ts:116 Uncaught (in promise) Error: TensorArray : Could not write to TensorArray index 0,
          because the value dtype is int32, but TensorArray dtype is float32.
      at e.write (tensor_array.ts:116)
      at tensor_array.ts:162
      at Array.forEach (<anonymous>)
      at e.writeMany (tensor_array.ts:162)
      at e.scatter (tensor_array.ts:252)
      at control_executor.ts:127
      at callbacks.ts:17
      at Object.next (callbacks.ts:17)
      at callbacks.ts:17```

     Test 2; ---- using tfjs-model/coco-ssd/demo ----------------------------------
      did yarn , yarn watch  

    I replaced the coo-ssd model which works correctly, with my re-trained model  (only switched the models)
      //BASE_PATH = "https://storage.googleapis.com/tfjs-models/savedmodel/";
        BASE_PATH = "http://localhost:1234/web_model/";
    //this.modelPath = "" + BASE_PATH + this.getPrefix(e) + 
    "/tensorflowjs_model.pb", this.weightPath = "" + BASE_PATH + 
    this.getPrefix(e) + "/weights_manifest.json";
    ``this.modelPath = "" + BASE_PATH +  "tensorflowjs_model.pb", 
      this.weightPath = "" +BASE_PATH + "weights_manifest.json";``

    I get an error
    io_utils.ts:116 Uncaught (in promise) RangeError: byte length of float32Array should be a multiple of 4
        at new Float32Array (<anonymous>)
        at o (io_utils.ts:116)
        at Object.decodeWeights (io_utils.ts:79)
        at e.<anonymous> (frozen_model.ts:109)
        at exports_regularizers.ts:47
        at Object.next (exports_regularizers.ts:47)
        at s (exports_regularizers.ts:47)```


    model loaded - now predict .. start ( i tried chaning the model to Coco-ssd model same error)
    ```tensor_array.ts:116 Uncaught (in promise) Error: TensorArray : Could not write to TensorArray index 0,
          because the value dtype is int32, but TensorArray dtype is float32.
        at e.write (tensor_array.ts:116)
        at tensor_array.ts:162
        at Array.forEach (<anonymous>)
        at e.writeMany (tensor_array.ts:162)
        at e.scatter (tensor_array.ts:252)
        at control_executor.ts:127```
        at callbacks.ts:17
        at Object.next (callbacks.ts:17)
        at callbacks.ts:17


image.src=imageURL;
var-img;
const runButton=document.getElementById('run');
runButton.onclick=async()=>{
log('modelstart');
常量模型=等待模型承诺;
log('model-loaded');
常数零=tf.zeros([1224224,3]);
常量批处理=tf.tidy(()=>{
if(!(tf.张量的图像实例)){
img=tf.fromPixels(图像);
}
//重塑为单个元素批处理,以便将其传递给executeAsync。
返回img.expandDims(0);
});
log('model loaded-now predict..start');
const result=await model.executeAsync(批处理);
log('model-loaded-now predict-ready');//看到错误
batched.dispose();
tf.处置(结果);
模型已加载-现在预测..开始(我尝试将模型更改为Coco ssd模型相同错误)
tensor_数组.ts:116未捕获(承诺中)错误:Tensorary:无法写入Tensorary索引0,
因为值dtype是int32,而TensorArray dtype是float32。
在e.write(张量数组ts:116)
在张量数组中。ts:162
在Array.forEach()处
在e.writeMany(张量数组:162)
在e.scatter(张量数组ts:252)
在控制室执行人ts:127
在回拨时。ts:17
at Object.next(callbacks.ts:17)
在回拨时。ts:17```
测试2;----使用tfjs模型/coco ssd/demo----------------------------------
你看了吗
我将正常工作的coo ssd型号替换为经过重新培训的型号(仅切换型号)
//基本路径=”https://storage.googleapis.com/tfjs-models/savedmodel/";
基本路径=”http://localhost:1234/web_model/";
//this.modelPath=”“+基本路径+this.getPrefix(e)+
“/tensorflowjs_model.pb”,this.weightPath=”“+BASE_PATH+
this.getPrefix(e)+“/weights\u manifest.json”;
``this.modelPath=”“+BASE_PATH+“tensorflowjs_model.pb”,
this.weightPath=”“+基本路径+“weights\u manifest.json”``
我犯了一个错误
io_utils.ts:116未捕获(承诺中)RangeError:float32Array的字节长度应为4的倍数
在新的Float32Array()上
at o(io_utils.ts:116)
在Object.decodeWeights(io_utils.ts:79)
在东面(冻结模式ts:109)
在出口处。ts:47
在Object.next(导出正则化子.ts:47)
在s(出口量:47)```
模型已加载-现在预测..开始(我尝试将模型更改为Coco ssd模型相同错误)
```tensor_数组.ts:116未捕获(承诺中)错误:Tensorary:无法写入Tensorary索引0,
因为值dtype是int32,而TensorArray dtype是float32。
在e.write(张量数组ts:116)
在张量数组中。ts:162
在Array.forEach()处
在e.writeMany(张量数组:162)
在e.scatter(张量数组ts:252)
在控制室执行人ts:127```
在回拨时。ts:17
at Object.next(callbacks.ts:17)
在回拨时。ts:17

该错误与您用于预测的张量图像有关

tf.fromPixel使用dtype int创建一个值范围为0到255的张量图像。由于您的模型正在等待dtype float32的张量,因此您可以将该类型强制转换为float,也可以将张量值更改为0到1之间

  • 铸造到浮动32
img=tf.fromPixels(image.cast('float32'))
  • 将值移动到0和1之间
img=tf.fromPixels(image).div(256)

试试这些转换参数。在使用mobilenet_v1进行重新培训后,这些参数对我有效 output_node_names=“后处理器/ExpandDims_1,后处理器/Slice”


< /P>我使用了CO-SDS-TunSoFalm模型示例代码,它工作了,然后我将Python Coco SSD模型转换成TysRoojjs模型,当使用相同的示例代码时,它也给出了相同的错误。这是一个转换问题吗?@集成,这里没有问题。考虑我的答案的更新,更多的解释Img= TF.FaskListar(图像)。('float32');不工作相同错误:TensorArray:无法写入TensorArray索引0,因为值dtype为int32,但TensorArray dtype为float32。更改张量的类型后,不能出现相同的错误。请确保tensor.dtype显示

float32
,因为model.predict正在等待float32dtype和casting到
float32
dtype或除以
256
将把dtype从
int32
更改为
float32
这里是我转换的ssd\u mobilenet\u v1\u coco\u 2017\u 11\u 17.tar.gz这是一个冻结的模型。运行这个转换tensorflowjs\u转换器--input\u format=tf\u freezed\u model–output\u node\u names='Postprocessor/ExpandDims_1,后处理器/Slice'--保存的_模型_标签=serve./冻结的_推理_graph.pb./web_模型_1--当我将原始jsmodel替换为转换后的模型时,与上述错误相同--未捕获(承诺中)RangeError:Float32Array的字节长度应为4Try的倍数this:tensorflowjs\u转换器--input\u format=tf\u saved\u模型--output\u node\u names=“后处理器/ExpandDims\u 1,后处理器/Slice”--saved_model_tags=服务saved_model web_model注:尝试转换最新型号:ssd_mobilenet_v1_coco_2018_01_28.tar我从2017年起就没有尝试过该型号。