ios – Loading custom tensor flow model into expo managed app


I created a simple classifier using tensor flow in python and saved like so

category = to_categorical(labels, num_classes=np.max(labels)+1)
model.fit(data, category, epochs=10, batch_size=16, validation_split=0.2)
tfjs.converters.save_keras_model(model, './js-model')

I now have the 2 model files, model.json and group1-shard1of1.bin

I added .bin extension to the metro config

But whenever I import the bin file, const bin = require("./js-model/group1-shard1of1.bin");
I get this error when bundling

rror: SyntaxError: /src/screens/session-screen/js-model/group1-shard1of1.bin: Unexpected character '�'. (1:1)
@acme/expo:dev: 
@acme/expo:dev: > 1 | a�5�:�<W��={Ӈ=1��`R�j�D=6_%=ݣ;-��ވ����=�D��e=�+�<�2����n�D�_=×�;aב�7��U

It seems like metro/react-native is unaware of the encoding/format of the bin file.

Any advice for this? Heres my dependencies

"@clerk/clerk-expo": "0.11.3",
    "@expo/config-plugins": "5.0.2",
    "@react-native-async-storage/async-storage": "^1.21.0",
    "@react-navigation/bottom-tabs": "^6.5.7",
    "@react-navigation/native": "^6.0.11",
    "@react-navigation/native-stack": "^6.7.0",
    "@react-navigation/stack": "^6.2.2",
    "@shopify/flash-list": "1.3.1",
    "@tanstack/react-query": "^4.16.1",
    "@tensorflow/tfjs": "^4.15.0",
    "@tensorflow/tfjs-react-native": "^1.0.0",
    "@trpc/client": "^10.1.0",
    "@trpc/react-query": "^10.1.0",
    "@trpc/server": "^10.1.0",
    "expo": "~47.0.14",
    "expo-auth-session": "~3.8.0",
    "expo-build-properties": "~0.4.1",
    "expo-camera": "~13.1.0",
    "expo-constants": "~14.0.2",
    "expo-font": "11.0.1",
    "expo-gl": "~12.0.1",
    "expo-gl-cpp": "^11.4.0",
    "expo-linking": "~3.3.1",
    "expo-modules-autolinking": "~1.0.0",
    "expo-random": "~13.0.0",
    "expo-secure-store": "~12.0.0",
    "expo-splash-screen": "~0.17.5",
    "expo-status-bar": "~1.4.2",
    "expo-updates": "~0.15.6",
    "expo-web-browser": "12.0.0",
    "javascript-time-ago": "^2.5.9",
    "nativewind": "^2.0.11",
    "react": "18.1.0",
    "react-dom": "18.1.0",
    "react-native": "0.70.8",

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img