hiukim / mind-ar-js

Web Augmented Reality. Image Tracking, Face Tracking. Tensorflow.js
MIT License
2.26k stars 423 forks source link

Issue trying new tensorflow version #10

Closed kalwalt closed 2 years ago

kalwalt commented 3 years ago

I tested the new version with tensorflow, i get this error:

A-Frame Version: 1.0.4 (Date 2020-02-05, Commit #2b359246)
mindar.prod.js:12858 three Version (https://github.com/supermedium/three.js): ^0.111.6
mindar.prod.js:12858 WebVR Polyfill Version: ^0.10.10
mindar.prod.js:12680 THREE.WebGLRenderer: WEBGL_depth_texture extension not supported.
get @ mindar.prod.js:12680
mindar.prod.js:12680 THREE.WebGLRenderer: OES_texture_float_linear extension not supported.
get @ mindar.prod.js:12680
mindar.prod.js:12658 video ready... <video autoplay muted playsinline style=​"position:​ absolute;​ top:​ 0px;​ left:​ -32px;​ z-index:​ -2;​ width:​ 384px;​ height:​ 512px;​" width=​"480" height=​"640">​</video>​
mindar.prod.js:10332 Could not get context for WebGL version 2
mindar.prod.js:10348 1    
2        precision highp float;
3        precision highp int;
4        precision highp sampler2D;
5        varying vec2 resultUV;
6        
7        const vec2 halfCR = vec2(0.5, 0.5);
8    
9        struct ivec5
10       {
11         int x;
12         int y;
13         int z;
14         int w;
15         int u;
16       };
mindar.prod.js:10348 Fragment shader compilation failed.
mindar.prod.js:10348  17                                                                                                      
mindar.prod.js:10348 18       struct ivec6
19       {
20         int x;
21         int y;
22         int z;
23         int w;
24         int u;
25         int v;
26       };
27   
28       uniform float NAN;
29       
30         #define isnan(value) isnan_custom(value)
31         bool isnan_custom(float val) {
32           return (val > 0. || val < 1. || val == 0.) ? false : true;
33         }
34         bvec4 isnan_custom(vec4 val) {
35           return bvec4(isnan(val.x), isnan(val.y), isnan(val.z), isnan(val.w));
36         }
37       
38       
39         uniform float INFINITY;
40   
41         bool isinf(float val) {
42           return abs(val) == INFINITY;
43         }
44         bvec4 isinf(vec4 val) {
45           return equal(abs(val), vec4(INFINITY));
46         }
47       
48       
49         int round(float value) {
50           return int(floor(value + 0.5));
51         }
52   
53         ivec4 round(vec4 value) {
54           return ivec4(floor(value + vec4(0.5)));
55         }
56       
57   
58       int imod(int x, int y) {
59         return x - y * (x / y);
60       }
61   
62       int idiv(int a, int b, float sign) {
63         int res = a / b;
64         int mod = imod(a, b);
65         if (sign < 0. && mod != 0) {
66           res -= 1;
67         }
68         return res;
69       }
70   
71       //Based on the work of Dave Hoskins
72       //https://www.shadertoy.com/view/4djSRW
73       #define HASHSCALE1 443.8975
74       float random(float seed){
75         vec2 p = resultUV * seed;
76         vec3 p3  = fract(vec3(p.xyx) * HASHSCALE1);
77         p3 += dot(p3, p3.yzx + 19.19);
78         return fract((p3.x + p3.y) * p3.z);
79       }
80   
81       
82   vec2 uvFromFlat(int texNumR, int texNumC, int index) {
83     int texR = index / texNumC;
84     int texC = index - texR * texNumC;
85     return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
86   }
87   vec2 packedUVfrom1D(int texNumR, int texNumC, int index) {
88     int texelIndex = index / 2;
89     int texR = texelIndex / texNumC;
90     int texC = texelIndex - texR * texNumC;
91     return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
92   }
93   
94       
95   vec2 packedUVfrom2D(int texelsInLogicalRow, int texNumR,
96     int texNumC, int row, int col) {
97     int texelIndex = (row / 2) * texelsInLogicalRow + (col / 2);
98     int texR = texelIndex / texNumC;
99     int texC = texelIndex - texR * texNumC;
100    return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
101  }
102  
103      
104  vec2 packedUVfrom3D(int texNumR, int texNumC,
105      int texelsInBatch, int texelsInLogicalRow, int b,
106      int row, int col) {
107    int index = b * texelsInBatch + (row / 2) * texelsInLogicalRow + (col / 2);
108    int texR = index / texNumC;
109    int texC = index - texR * texNumC;
110    return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
111  }
112  
113    
114  
115      float sampleTexture(sampler2D textureSampler, vec2 uv) {
116        return texture2D(textureSampler, uv).r;
117      }
118    
119  
120      void setOutput(vec4 val) {
121        gl_FragColor = val;
122      }
123    
124  uniform sampler2D A;
125  uniform int offsetA;
126  
127      ivec3 getOutputCoords() {
128        ivec2 resTexRC = ivec2(resultUV.yx *
129                               vec2(160, 160));
130        int index = resTexRC.x * 160 + resTexRC.y;
131  
132        int b = index / 25500;
133        index -= b * 25500;
134  
135        int r = 2 * (index / 510);
136        int c = imod(index, 510) * 2;
137  
138        return ivec3(b, r, c);
139      }
140    
141  
142          
143      float getA(int row, int col) {
144        vec2 uv = (vec2(col, row) + halfCR) / vec2(1020.0, 100.0);
145        return sampleTexture(A, uv);
146      }
147    
148          float getA(int row, int col, int depth) {
149            return getA(col, depth);
150          }
151        
152      float getAAtOutCoords() {
153        ivec3 coords = getOutputCoords();
154        
155        return getA(coords.x, coords.y, coords.z);
156      }
157    
158  
159        ivec3 outCoordsFromFlatIndex(int index) {
160          int r = index / 102000; index -= r * 102000;int c = index / 1020; int d = index - c * 1020;
161          return ivec3(r, c, d);
162        }
163  
164        void main() {
165          ivec2 resTexRC = ivec2(resultUV.yx *
166            vec2(160, 160));
167          int index = 4 * (resTexRC.x * 160 + resTexRC.y);
168  
169          vec4 result = vec4(0.);
170  
171          for (int i=0; i<4; i++) {
172            int flatIndex = index + i;
173            ivec3 rc = outCoordsFromFlatIndex(flatIndex);
174            result[i] = getA(rc.x, rc.y, rc.z);
175          }
176  
177          gl_FragColor = result;
178        }
179      
mindar.prod.js:10348 Uncaught (in promise) Error: Failed to compile fragment shader.
    at mf (mindar.prod.js:10348)
    at dg.createProgram (mindar.prod.js:10911)
    at mindar.prod.js:11440
    at mindar.prod.js:11440
    at vb.getAndSaveBinary (mindar.prod.js:11440)
    at vb.runWebGLProgram (mindar.prod.js:11440)
    at vb.decode (mindar.prod.js:11440)
    at vb.getValuesFromTexture (mindar.prod.js:11440)
    at vb.readSync (mindar.prod.js:11440)
    at g.readSync (mindar.prod.js:4141)

Tested with a Wiko View, with Android 7.1.2. Chrome 87.0.4280.141.

hiukim commented 3 years ago

@kalwalt Sorry, I still couldn't replicate this error.

Maybe can you try running any tensorflowjs example first? https://www.tensorflow.org/js/demos

kalwalt commented 3 years ago

@kalwalt Sorry, I still couldn't replicate this error.

Maybe can you try running any tensorflowjs example first? https://www.tensorflow.org/js/demos

i will try again also with other devices and will test the examples you suggested :slightly_smiling_face:

hiukim commented 3 years ago

Thanks a lot! appreciated!

hiukim commented 3 years ago

@kalwalt Just bumped the tfjs version from 2.x to 3.6. Not sure it helps, but worth a try.

kalwalt commented 3 years ago

@kalwalt Just bumped the tfjs version from 2.x to 3.6. Not sure it helps, but worth a try.

Thank you for the news! I will test It.

kalwalt commented 3 years ago

@hiukim with my new Oppo A72 works fine all the examples! i will test also with my oldest device.

hiukim commented 3 years ago

@kalwalt good news! thanks for testing.