mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-01-09 15:08:02 -05:00
Fix yolo load failing silently (#10046)
* wait for js before loading model * use f32 * revert html changes, try both cameras and remove f16 req * clean
This commit is contained in:
@@ -127,14 +127,22 @@
|
|||||||
const offscreenContext = offscreenCanvas.getContext('2d');
|
const offscreenContext = offscreenCanvas.getContext('2d');
|
||||||
|
|
||||||
|
|
||||||
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
|
if (navigator.mediaDevices?.getUserMedia) {
|
||||||
navigator.mediaDevices.getUserMedia({ audio: false, video: { facingMode: { ideal: "environment" }}}).then(function (stream) {
|
const tryCamera = facing => navigator.mediaDevices.getUserMedia({ audio: false, video: { facingMode: { ideal: facing } } });
|
||||||
|
const handle = stream => {
|
||||||
video.srcObject = stream;
|
video.srcObject = stream;
|
||||||
video.onloadedmetadata = function() {
|
video.onloadedmetadata = function() {
|
||||||
canvas.width = video.clientWidth;
|
canvas.width = video.clientWidth;
|
||||||
canvas.height = video.clientHeight;
|
canvas.height = video.clientHeight;
|
||||||
}
|
};
|
||||||
});
|
};
|
||||||
|
tryCamera("environment").then(handle).catch(() =>
|
||||||
|
tryCamera("user").then(handle).catch(e => {
|
||||||
|
wgpuError.textContent = "Error: Could not access camera."
|
||||||
|
wgpuError.style.display = "block";
|
||||||
|
loadingContainer.style.display = "none";
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processFrame() {
|
async function processFrame() {
|
||||||
@@ -246,7 +254,6 @@
|
|||||||
if (!navigator.gpu) return false;
|
if (!navigator.gpu) return false;
|
||||||
const adapter = await navigator.gpu.requestAdapter();
|
const adapter = await navigator.gpu.requestAdapter();
|
||||||
return await adapter.requestDevice({
|
return await adapter.requestDevice({
|
||||||
requiredFeatures: ["shader-f16"],
|
|
||||||
powerPreference: "high-performance"
|
powerPreference: "high-performance"
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -352,13 +352,9 @@ def postprocess(output, max_det=300, conf_threshold=0.25, iou_threshold=0.45):
|
|||||||
def get_weights_location(yolo_variant: str) -> Path:
|
def get_weights_location(yolo_variant: str) -> Path:
|
||||||
weights_location = Path(__file__).parents[1] / "weights" / f'yolov8{yolo_variant}.safetensors'
|
weights_location = Path(__file__).parents[1] / "weights" / f'yolov8{yolo_variant}.safetensors'
|
||||||
fetch(f'https://gitlab.com/r3sist/yolov8_weights/-/raw/master/yolov8{yolo_variant}.safetensors', weights_location)
|
fetch(f'https://gitlab.com/r3sist/yolov8_weights/-/raw/master/yolov8{yolo_variant}.safetensors', weights_location)
|
||||||
|
f32_weights = weights_location.with_name(f"{weights_location.stem}_f32.safetensors")
|
||||||
if not is_dtype_supported(dtypes.half):
|
if not f32_weights.exists(): convert_f16_safetensor_to_f32(weights_location, f32_weights)
|
||||||
f32_weights = weights_location.with_name(f"{weights_location.stem}_f32.safetensors")
|
return f32_weights
|
||||||
if not f32_weights.exists(): convert_f16_safetensor_to_f32(weights_location, f32_weights)
|
|
||||||
weights_location = f32_weights
|
|
||||||
|
|
||||||
return weights_location
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user