()
| 88 | device.queue.writeBuffer(sizeParamBuffer, 0, new Int32Array([sizeParams.width, sizeParams.height])); |
| 89 | |
| 90 | const predict = async () => { |
| 91 | beginEstimateSegmentationStats(); |
| 92 | const segmentationConfig = {flipHorizontal: false, multiSegmentation: false, segmentBodyParts: true, |
| 93 | segmentationThreshold: 0.5}; |
| 94 | const segmentation = await model.segmentPeople(video, segmentationConfig); |
| 95 | |
| 96 | const tensor = await segmentation[0].mask.toTensor(); |
| 97 | const data = tensor.dataToGPU(); |
| 98 | |
| 99 | const uniformBindGroup = device.createBindGroup({ |
| 100 | layout: pipeline.getBindGroupLayout(0), |
| 101 | entries: [ |
| 102 | { |
| 103 | binding: 1, |
| 104 | resource: sampler, |
| 105 | }, |
| 106 | { |
| 107 | binding: 2, |
| 108 | resource: device.importExternalTexture({ |
| 109 | source: video, |
| 110 | }), |
| 111 | }, |
| 112 | { |
| 113 | binding: 3, |
| 114 | resource: { |
| 115 | buffer: data.buffer, |
| 116 | }, |
| 117 | }, |
| 118 | { |
| 119 | binding: 4, |
| 120 | resource: { |
| 121 | buffer: sizeParamBuffer, |
| 122 | }, |
| 123 | } |
| 124 | ], |
| 125 | }); |
| 126 | |
| 127 | const commandEncoder = device.createCommandEncoder(); |
| 128 | const textureView = context.getCurrentTexture().createView(); |
| 129 | |
| 130 | const renderPassDescriptor = { |
| 131 | colorAttachments: [ |
| 132 | { |
| 133 | view: textureView, |
| 134 | clearValue: { r: 0.0, g: 0.0, b: 0.0, a: 1.0 }, |
| 135 | loadOp: 'clear', |
| 136 | storeOp: 'store', |
| 137 | }, |
| 138 | ], |
| 139 | }; |
| 140 | |
| 141 | const passEncoder = commandEncoder.beginRenderPass(renderPassDescriptor); |
| 142 | passEncoder.setPipeline(pipeline); |
| 143 | passEncoder.setBindGroup(0, uniformBindGroup); |
| 144 | passEncoder.draw(6, 1, 0, 0); |
| 145 | passEncoder.end(); |
| 146 | device.queue.submit([commandEncoder.finish()]); |
| 147 | tensor.dispose(); |
nothing calls this directly
no test coverage detected