Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ export class TestRunner extends Component<TestRunnerProps, TestRunnerState> {
// Browser specific mobile test
return false;
}

if(name.match('dilation2d')) {
// Not implemented in webgl
return false;
}
return true;
}
});
Expand Down
2 changes: 1 addition & 1 deletion tfjs-react-native/integration_rn59/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@tensorflow-models/blazeface": "^0.0.2",
"@tensorflow-models/mobilenet": "^2.0.4",
"@tensorflow-models/posenet": "^2.2.1",
"@tensorflow/tfjs": "2.0.0",
"@tensorflow/tfjs": "2.6.0",
"@tensorflow/tfjs-react-native": "0.3.0",
"expo-camera": "^7.0.0",
"expo-gl": "^7.0.0",
Expand Down
197 changes: 153 additions & 44 deletions tfjs-react-native/integration_rn59/yarn.lock

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions tfjs-react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
},
"devDependencies": {
"@react-native-community/async-storage": "^1.4.2",
"@tensorflow/tfjs-backend-cpu": "~2.0.0",
"@tensorflow/tfjs-backend-webgl": "~2.0.0",
"@tensorflow/tfjs-core": "~2.0.0",
"@tensorflow/tfjs-backend-cpu": "~2.6.0",
"@tensorflow/tfjs-backend-webgl": "~2.6.0",
"@tensorflow/tfjs-core": "~2.6.0",
"@types/base64-js": "^1.2.5",
"@types/jasmine": "~3.3.0",
"@types/react-native": "0.60.2",
Expand Down Expand Up @@ -64,7 +64,9 @@
},
"peerDependencies": {
"@react-native-community/async-storage": "^1.4.2",
"@tensorflow/tfjs-backend-webgl": "~2.0.0",
"@tensorflow/tfjs-backend-webgl": "~2.6.0",
"@tensorflow/tfjs-backend-cpu": "~2.6.0",
"@tensorflow/tfjs-core": "~2.6.0",
"expo-asset": "^7.0.0",
"expo-camera": "^7.0.0",
"expo-gl": "^7.0.0",
Expand Down
8 changes: 4 additions & 4 deletions tfjs-react-native/src/camera/camera_stream.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ const DEFAULT_RESIZE_DEPTH = 3;
* component with the ability to yield tensors representing the camera stream.
*
* Because the camera data will be consumed in the process, the original
* camera component will not render any content. A provided by this component
* is used to render the camera preview.
* camera component will not render any content. This component provides
* options that can be used to render the camera preview.
*
* Notably the component allows on-the-fly resizing of the camera image to
* smaller dimensions, this speeds up data transfer between the native and
Expand Down Expand Up @@ -306,9 +306,9 @@ export function cameraWithTensors<T extends WrappedComponentProps>(
const height = PixelRatio.getPixelSizeForLayoutSize(
cameraLayout.height
);
const isFrontCamera =
const isFrontCamera =
this.camera.props.type === Camera.Constants.Type.front;
const flipHorizontal =
const flipHorizontal =
Platform.OS === 'ios' && isFrontCamera ? false : true;

renderToGLView(gl, cameraTexture, { width, height }, flipHorizontal);
Expand Down
31 changes: 11 additions & 20 deletions tfjs-react-native/src/camera/camera_webgl_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import {webgl_util} from '@tensorflow/tfjs-backend-webgl';
import * as tf from '@tensorflow/tfjs-core';

import {getDebugMode} from '../platform_react_native';

import * as drawTextureProgramInfo from './draw_texture_program_info';
import * as resizeBilinearProgramInfo from './resize_bilinear_program_info';
import * as resizeNNProgramInfo from './resize_nearest_neigbor_program_info';
Expand Down Expand Up @@ -68,32 +66,30 @@ export function downloadTextureData(
}
const fbo = fboCache.get(gl);

const debugMode = getDebugMode();

webgl_util.callAndCheck(gl, debugMode, () => {
webgl_util.callAndCheck(gl, () => {
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
});

webgl_util.callAndCheck(gl, debugMode, () => {
webgl_util.callAndCheck(gl, () => {
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, texture);
});

webgl_util.callAndCheck(gl, debugMode, () => {
webgl_util.callAndCheck(gl, () => {
const level = 0;
gl.framebufferTexture2D(
gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, level);
});

webgl_util.callAndCheck(gl, debugMode, () => {
webgl_util.callAndCheck(gl, () => {
const format = depth === 3 ? gl.RGB : gl.RGBA;
const x = 0;
const y = 0;
gl.readPixels(x, y, width, height, format, gl.UNSIGNED_BYTE, pixels);
});

// Unbind framebuffer
webgl_util.callAndCheck(gl, debugMode, () => {
webgl_util.callAndCheck(gl, () => {
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
});
return pixels;
Expand Down Expand Up @@ -128,15 +124,13 @@ export function uploadTextureData(
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);

const debugMode = getDebugMode();

const level = 0;
const format = dims.depth === 3 ? gl.RGB : gl.RGBA;
const internalFormat = format;
const border = 0;
const type = gl.UNSIGNED_BYTE;

webgl_util.callAndCheck(gl, debugMode, () => {
webgl_util.callAndCheck(gl, () => {
gl.texImage2D(
gl.TEXTURE_2D, level, internalFormat, targetTextureWidth,
targetTextureHeight, border, format, type, imageData);
Expand Down Expand Up @@ -183,13 +177,11 @@ export function runResizeProgram(
gl: WebGL2RenderingContext, inputTexture: WebGLTexture,
inputDims: Dimensions, outputDims: Dimensions, alignCorners: boolean,
interpolation: 'nearest_neighbor'|'bilinear') {
const debugMode = getDebugMode();

const {program, vao, vertices, uniformLocations} =
resizeProgram(gl, inputDims, outputDims, alignCorners, interpolation);
gl.useProgram(program);
// Set up geometry
webgl_util.callAndCheck(gl, debugMode, () => {
webgl_util.callAndCheck(gl, () => {
gl.bindVertexArray(vao);
});

Expand Down Expand Up @@ -235,7 +227,7 @@ export function runResizeProgram(
const border = 0;
const type = gl.UNSIGNED_BYTE;

webgl_util.callAndCheck(gl, debugMode, () => {
webgl_util.callAndCheck(gl, () => {
gl.texImage2D(
gl.TEXTURE_2D, level, internalFormat, targetTextureWidth,
targetTextureHeight, border, format, type, null);
Expand Down Expand Up @@ -365,7 +357,6 @@ function createProgramObjects(
gl: WebGL2RenderingContext, vertexShaderSource: string,
fragmentShaderSource: string, vertices: Float32Array,
texCoords: Float32Array): ProgramObjects {
const debugMode = getDebugMode();
const vertShader = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(vertShader, vertexShaderSource);
gl.compileShader(vertShader);
Expand All @@ -385,7 +376,7 @@ function createProgramObjects(
gl.bindVertexArray(vao);

// Set up geometry
webgl_util.callAndCheck(gl, debugMode, () => {
webgl_util.callAndCheck(gl, () => {
const positionAttrib = gl.getAttribLocation(program, 'position');
const vertsCoordsBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertsCoordsBuffer);
Expand All @@ -395,7 +386,7 @@ function createProgramObjects(
gl.bindBuffer(gl.ARRAY_BUFFER, null);
});

webgl_util.callAndCheck(gl, debugMode, () => {
webgl_util.callAndCheck(gl, () => {
const texCoordsAttrib = gl.getAttribLocation(program, 'texCoords');
const texCoordsBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, texCoordsBuffer);
Expand All @@ -406,7 +397,7 @@ function createProgramObjects(
});

const uniformLocations = new Map<string, WebGLUniformLocation>();
webgl_util.callAndCheck(gl, debugMode, () => {
webgl_util.callAndCheck(gl, () => {
const inputTextureLoc = gl.getUniformLocation(program, 'inputTexture');
uniformLocations.set('inputTexture', inputTextureLoc);
});
Expand Down
9 changes: 0 additions & 9 deletions tfjs-react-native/src/platform_react_native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ import {Buffer} from 'buffer';
import {GLView} from 'expo-gl';
import {Platform as RNPlatform} from 'react-native';

let debugMode_ = false;
export function setDebugMode(debugMode: boolean) {
debugMode_ = debugMode_;
}

export function getDebugMode() {
return debugMode_;
}

// See implemetation note on fetch
// tslint:disable-next-line:max-line-length
// https://github.com/facebook/react-native/blob/0ee5f68929610106ee6864baa04ea90be0fc5160/Libraries/vendor/core/whatwg-fetch.js#L421
Expand Down
36 changes: 18 additions & 18 deletions tfjs-react-native/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -35,36 +35,36 @@
dependencies:
defer-to-connect "^1.0.1"

"@tensorflow/tfjs-backend-cpu@2.0.0-rc.3":
version "2.0.0-rc.3"
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-backend-cpu/-/tfjs-backend-cpu-2.0.0-rc.3.tgz#cadcc99a366c13e9c346f78b23ceff8375cfc46b"
integrity sha512-qwg0GmfVRPaF4bMrzpWV2fcTnvU5f6UxsOySgso+3id3KbQmh89XZGtSLUJL4iw8P6HIxNiR++KJkygmQFWhDA==
"@tensorflow/tfjs-backend-cpu@2.6.0", "@tensorflow/tfjs-backend-cpu@~2.6.0":
version "2.6.0"
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-backend-cpu/-/tfjs-backend-cpu-2.6.0.tgz#bd0923ca438e945c4c9347a76e301a4fb1890d33"
integrity sha512-essk82VoET77tuFX5Sa9zv9F8d/2DxjEQ2RavoU+ugs0l64DTbdTpv3WdQwUihv1gNN7/16fUjJ6cG80SnS8/g==
dependencies:
"@types/seedrandom" "2.4.27"
seedrandom "2.4.3"

"@tensorflow/tfjs-backend-webgl@2.0.0-rc.3":
version "2.0.0-rc.3"
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-backend-webgl/-/tfjs-backend-webgl-2.0.0-rc.3.tgz#6bf36de6be2a7fecec17d1bce57daa233722685c"
integrity sha512-iWsuQ5M21lHulLwkAF1KilzCvXT1WCumCYcdYrBzKNT9Ghi0YoNbcoT8s1RRli2jhgy/YqBLLaRFXy9s0kJb0A==
"@tensorflow/tfjs-backend-webgl@~2.6.0":
version "2.6.0"
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-backend-webgl/-/tfjs-backend-webgl-2.6.0.tgz#3855c254a86daf28511530c36bb61938acf26740"
integrity sha512-j1eNYKIpO06CTSRXiIWdpZ2iPDBkx7PPl7K/1BtCEW/9FP7Q0q3doHKNmTdOPvuw7Dt1nNHEMnba0YB2lc5S7Q==
dependencies:
"@tensorflow/tfjs-backend-cpu" "2.0.0-rc.3"
"@tensorflow/tfjs-backend-cpu" "2.6.0"
"@types/offscreencanvas" "~2019.3.0"
"@types/seedrandom" "2.4.27"
"@types/webgl-ext" "0.0.30"
"@types/webgl2" "0.0.4"
seedrandom "2.4.3"

"@tensorflow/tfjs-core@2.0.0-rc.3":
version "2.0.0-rc.3"
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-core/-/tfjs-core-2.0.0-rc.3.tgz#a665a1a4106c6bc802762c4a4f022d4971908cd2"
integrity sha512-EvsGWWwoDX3lD7YujlMlv9DRCKAEZevzWjO5cE8vJnZkVToQ3B5l5fsUH2eGoe/+6FHUPr2HfkwU/492/sfOiQ==
"@tensorflow/tfjs-core@~2.6.0":
version "2.6.0"
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-core/-/tfjs-core-2.6.0.tgz#ab2f2c9e8f46990643076d7d5bdb912885282bd2"
integrity sha512-akUB1iz663UCUdOfEUu91XeHzGpdYtdtMPxjsGEdF0CwENzSAcvHzQrEVoPBRD+RKpxrVXvQBoOd7GYBxMIIKQ==
dependencies:
"@types/offscreencanvas" "~2019.3.0"
"@types/seedrandom" "2.4.27"
"@types/webgl-ext" "0.0.30"
"@types/webgl2" "0.0.4"
node-fetch "~2.1.2"
node-fetch "~2.6.1"
seedrandom "2.4.3"

"@types/base64-js@^1.2.5":
Expand Down Expand Up @@ -1195,10 +1195,10 @@ ncp@^2.0.0:
resolved "https://registry.yarnpkg.com/ncp/-/ncp-2.0.0.tgz#195a21d6c46e361d2fb1281ba38b91e9df7bdbb3"
integrity sha1-GVoh1sRuNh0vsSgbo4uR6d9727M=

node-fetch@~2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.1.2.tgz#ab884e8e7e57e38a944753cec706f788d1768bb5"
integrity sha1-q4hOjn5X44qUR1POxwb3iNF2i7U=
node-fetch@~2.6.1:
version "2.6.1"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==

normalize-package-data@^2.3.2, normalize-package-data@^2.3.4:
version "2.5.0"
Expand Down