Add bytes model loading test to react native e2e (#17749)

### Description
<!-- Describe your changes. -->
Update E2E test to also check InferenceSession.create with bytes. 


### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
Add tests to validate #17739
This commit is contained in:
Scott McKay 2023-10-02 12:25:28 +10:00 committed by GitHub
parent 63acaf47d2
commit ac4e726046
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View file

@ -10,7 +10,8 @@
},
"dependencies": {
"react": "^18.1.0",
"react-native": "^0.69.1"
"react-native": "^0.69.1",
"react-native-fs": "^2.20.0"
},
"devDependencies": {
"@babel/core": "^7.17.0",

View file

@ -8,6 +8,7 @@ import { Image, Text, TextInput, View } from 'react-native';
import { InferenceSession, Tensor } from 'onnxruntime-react-native';
import MNIST, { MNISTInput, MNISTOutput, MNISTResult, } from './mnist-data-handler';
import { Buffer } from 'buffer';
import { readFile } from 'react-native-fs';
interface State {
session:
@ -39,10 +40,21 @@ export default class App extends React.PureComponent<{}, State> {
this.setState({ imagePath });
const modelPath = await MNIST.getLocalModelPath();
const session: InferenceSession = await InferenceSession.create(modelPath);
// test creating session with path
console.log('Creating with path');
const pathSession: InferenceSession = await InferenceSession.create(modelPath);
pathSession.release();
// and with bytes
console.log('Creating with bytes');
const base64Str = await readFile(modelPath, 'base64');
const bytes = Buffer.from(base64Str, 'base64');
const session: InferenceSession = await InferenceSession.create(bytes);
this.setState({ session });
void this.infer();
console.log('Test session created');
void await this.infer();
} catch (err) {
console.log(err.message);
}