Skip to content

Commit

Permalink
Add bytes model loading test to react native e2e (#17749)
Browse files Browse the repository at this point in the history
### 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
  • Loading branch information
skottmckay authored Oct 2, 2023
1 parent 63acaf4 commit ac4e726
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion js/react_native/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 14 additions & 2 deletions js/react_native/e2e/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit ac4e726

Please sign in to comment.