ModelDepot / tfjs-yolo-tiny

In-Browser Object Detection using Tiny YOLO on Tensorflow.js
https://modeldepot.io/mikeshi/tiny-yolo-in-javascript
MIT License
530 stars 92 forks source link

Not working on Andriod Phone #11

Closed wpitallo closed 6 years ago

wpitallo commented 6 years ago

I try to run the demo, from the demo page on my Android phone, the camera starts streaming but there is no image detection happening?

wpitallo commented 6 years ago

WebGL: CONTEXT_LOST_WEBGL: loseContext: context lost

src.367e2190.js:269 Uncaught (in promise) Error: Failed to compile fragment shader. at Object.s [as createFragmentShader] (src.367e2190.js:269) at a.createProgram (src.367e2190.js:303) at Object.n [as compileProgram] (src.367e2190.js:305) at src.367e2190.js:339 at F.getAndSaveBinary (src.367e2190.js:339) at F.compileAndRun (src.367e2190.js:339) at F.gather (src.367e2190.js:339) at r.ENV.engine.runKernel.x (src.367e2190.js:200) at c.runKernel (src.367e2190.js:262) at h.gather (src.367e2190.js:200)

wpitallo commented 6 years ago

Couldn't parse line number in error: src.367e2190.js:269 precision highp float; precision highp int; varying vec2 resultUV; const vec2 halfCR = vec2(0.5, 0.5);

bool isNaN(float val) { float v1 = val val; float v2 = val val; return v1 == v2 ? false : true; }

bool hasNaN(vec4 values) { vec4 v1 = values values; vec4 v2 = values values; return any(notEqual(v1, v2)); }

float getNaN(vec4 values) { return dot(vec4(1), values); }

int round(float value) { return int(floor(value + 0.5)); }

int imod(int x, int y) { return x - y * (x / y); }

const vec2 randomConst = vec2( 23.14069263277926, // e^pi (Gelfond's constant) 2.665144142690225 // 2^sqrt(2) (Gelfond–Schneider constant) );

float random(float seed) { return fract(cos(dot(resultUV seed, randomConst)) 12345.6789); }

vec2 UVfrom1D(int texNumR, int texNumC, int index) { int texR = index / texNumC; int texC = index - texR * texNumC; return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR); }

vec2 UVfrom2D(int texNumR, int texNumC, int numC, int row, int col) { int index = row numC + col; int texR = index / texNumC; int texC = index - texR texNumC; return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR); }

vec2 UVfrom3D(int texNumR, int texNumC, int stride0, int stride1, int row, int col, int depth) { // Explicitly use integer operations as dot() only works on floats. int index = row stride0 + col stride1 + depth; int texR = index / texNumC; int texC = index - texR * texNumC; return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR); }

vec2 UVfrom4D(int texNumR, int texNumC, int stride0, int stride1, int stride2, int row, int col, int depth, int depth2) { // Explicitly use integer operations as dot() only works on floats. int index = row stride0 + col stride1 + depth stride2 + depth2; int texR = index / texNumC; int texC = index - texR texNumC; return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR); }

float sampleTexture(sampler2D textureSampler, vec2 uv) { return texture2D(textureSampler, uv).r; }

void setOutput(float val) { gl_FragColor = vec4(val, 0, 0, 0); }

uniform sampler2D A; uniform sampler2D indices;

  ivec2 getOutputCoords() {
    return ivec2(resultUV.yx * vec2(55, 4));
  }

float getAFlat(int index) {
  vec2 uv = UVfrom1D(845, 4, index);
  return sampleTexture(A, uv);
}

float getA(int row, int col) {
  vec2 uv = (vec2(col, row) + halfCR) / vec2(4.0, 845.0);
  return sampleTexture(A, uv);
}

  float getIndicesFlat(int index) {
    vec2 uv = vec2(0.5, (float(index) + 0.5) / 55.0);
    return sampleTexture(indices, uv);
  }

float getIndices(int index) {
  return getIndicesFlat(index);
}

  void main() {
    ivec2 resRC = getOutputCoords();
    setOutput(getA(int(getIndices(resRC.x)),resRC.y));
  }
MikeShi42 commented 6 years ago

This sounds like an upstream tf.js issue, can you try running another demo perhaps Posenet? https://storage.googleapis.com/tfjs-models/demos/posenet/camera.html

owenljn commented 6 years ago

I have the same issue here, can anyone help? I've setup my own AWS instance for this demo, it works on computers but it doesn't work on cellphones. The code is the same, just different device, weird.

MikeShi42 commented 6 years ago

@owenljn I've tested on iPads and iPhones and it'll work for both. I don't have an android device to test on though. Can you try the Posenet demo above and let me know if it'll work on the device you're trying it out on? The error reported in this issue seems to stem from TF.js, though I can't be completely sure.

owenljn commented 6 years ago

@MikeShi42 Sorry actually it's not something wrong with the code, in fact, something went wrong when I try to host your code in an AWS instance, the code runs perfectly on conventional computers, but it doesn't do detection on my cellphone. And I tried both of your live demos on my cellphone and I can verify they do work.

MikeShi42 commented 6 years ago

@owenljn could it be that you're using latest tfjs? There seems to be an issue of version 0.11 and above. If you're running 0.10 it should work

See: https://github.com/ModelDepot/tfjs-yolo-tiny/issues/10