mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-30 20:18:08 +00:00
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:
parent
63acaf47d2
commit
ac4e726046
2 changed files with 16 additions and 3 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue