Skip to content

Fashion Mnist model #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
112 changes: 112 additions & 0 deletions entry/src/main/ets/MainAbility/pages/FashionMnist.ets

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion entry/src/main/ets/MainAbility/pages/index.ets
Original file line number Diff line number Diff line change
@@ -211,10 +211,14 @@ struct Index {
.onClick(() => {
router.push({ uri: 'pages/SelfieSegmentation' })
}).margin('25px')
Button("hand detection") // Load pretrained hand detection model
Button("hand detection") // Load pretrained hand detection model
.onClick(() => {
router.push({ uri: 'pages/handpose' })
}).margin('25px')
Button("Fashion Mnist") // Load pretrained Fashion Mnist model
.onClick(() => {
router.push({ uri: 'pages/FashionMnist' })
}).margin('25px')
}
.width('100%')
}
Binary file added entry/src/main/resources/base/media/pullover.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added entry/src/main/resources/base/media/tshirt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 38 additions & 1 deletion tfjs-core/src/io/res_system.ets
Original file line number Diff line number Diff line change
@@ -209,6 +209,9 @@ export class NodeFileSystem implements IOHandler {
else if (path==('/handpose')){
myData = await import('@ohos/tfjs-models/models/handpose/model.json');
}
else if(path==('/fashion')){
myData = await import('@ohos/tfjs-models/models/fashion/model.json');
}
console.info("myData " + myData);
let data = JSON.parse((JSON.stringify(myData)));
console.info(data.format);
@@ -389,6 +392,37 @@ export class NodeFileSystem implements IOHandler {
})
});
}
else if(path ==('/fashion')){
import('@ohos/tfjs-models/models/fashion/model.json').then(({default: myData}) => {
console.info("myData " + myData);
Promise.resolve(JSON.parse((JSON.stringify(myData))))
.then(data => {
/*console.info(data);
console.info(data.modelTopology);*/
console.info(data.format);

const modelTopology = data.modelTopology;
if (modelTopology == null) {
console.info("myData modelTopology null ");
reject(new Error(`modelTopology field is missing from file `));
return;
}
const weightsManifest = data.weightsManifest;
if (weightsManifest == null) {
console.info("myData weightsManifest null ");
reject(new Error(`weightManifest field is missing from file `));
return;
}
/*const modelArtifactsPromise = getModelArtifactsForJSON(
data, (weightsManifest) => this.loadWeights(weightsManifest));
resolve(modelArtifactsPromise);*/

return getModelArtifactsForJSON(
data,
(weightsManifest) => this.loadWeights(weightsManifest, ""));
})
});
}
});
}

@@ -453,7 +487,10 @@ export class NodeFileSystem implements IOHandler {
}
else if (path==('/handpose')){
jsonOfWeights = await import('@ohos/tfjs-models/models/handpose/weights.json');
}
}
else if(path==('/fashion')){
jsonOfWeights = await import('@ohos/tfjs-models/models/fashion/weights.json');
}
let jsonObj = JSON.parse(JSON.stringify(jsonOfWeights))
let jsonArray = []
for (var item in jsonObj) {
1 change: 1 addition & 0 deletions tfjs-models/models/fashion/model.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"format": "graph-model", "generatedBy": "2.8.2", "convertedBy": "TensorFlow.js Converter v1.7.0", "signature": {"inputs": {"conv2d_22_input": {"name": "conv2d_22_input:0", "dtype": "DT_FLOAT", "tensorShape": {"dim": [{"size": "-1"}, {"size": "28"}, {"size": "28"}, {"size": "1"}]}}}, "outputs": {"activation_35": {"name": "Identity:0", "dtype": "DT_FLOAT", "tensorShape": {"dim": [{"size": "-1"}, {"size": "10"}]}}}}, "modelTopology": {"node": [{"name": "StatefulPartitionedCall/sequential_6/flatten_6/Const", "op": "Const", "attr": {"dtype": {"type": "DT_INT32"}, "value": {"tensor": {"dtype": "DT_INT32", "tensorShape": {"dim": [{"size": "2"}]}}}}}, {"name": "StatefulPartitionedCall/sequential_6/dense_12/MatMul/ReadVariableOp", "op": "Const", "attr": {"dtype": {"type": "DT_FLOAT"}, "value": {"tensor": {"dtype": "DT_FLOAT", "tensorShape": {"dim": [{"size": "1024"}, {"size": "512"}]}}}}}, {"name": "StatefulPartitionedCall/sequential_6/dense_12/BiasAdd/ReadVariableOp", "op": "Const", "attr": {"dtype": {"type": "DT_FLOAT"}, "value": {"tensor": {"dtype": "DT_FLOAT", "tensorShape": {"dim": [{"size": "512"}]}}}}}, {"name": "StatefulPartitionedCall/sequential_6/batch_normalization_29/batchnorm/mul", "op": "Const", "attr": {"dtype": {"type": "DT_FLOAT"}, "value": {"tensor": {"dtype": "DT_FLOAT", "tensorShape": {"dim": [{"size": "512"}]}}}}}, {"name": "StatefulPartitionedCall/sequential_6/batch_normalization_29/batchnorm/sub", "op": "Const", "attr": {"value": {"tensor": {"dtype": "DT_FLOAT", "tensorShape": {"dim": [{"size": "512"}]}}}, "dtype": {"type": "DT_FLOAT"}}}, {"name": "StatefulPartitionedCall/sequential_6/dense_13/MatMul/ReadVariableOp", "op": "Const", "attr": {"dtype": {"type": "DT_FLOAT"}, "value": {"tensor": {"dtype": "DT_FLOAT", "tensorShape": {"dim": [{"size": "512"}, {"size": "10"}]}}}}}, {"name": "StatefulPartitionedCall/sequential_6/dense_13/BiasAdd/ReadVariableOp", "op": "Const", "attr": {"dtype": {"type": "DT_FLOAT"}, "value": {"tensor": {"dtype": "DT_FLOAT", "tensorShape": {"dim": [{"size": "10"}]}}}}}, {"name": "conv2d_22_input", "op": "Placeholder", "attr": {"shape": {"shape": {"dim": [{"size": "-1"}, {"size": "28"}, {"size": "28"}, {"size": "1"}]}}, "dtype": {"type": "DT_FLOAT"}}}, {"name": "StatefulPartitionedCall/sequential_6/conv2d_22/Conv2D_weights", "op": "Const", "attr": {"value": {"tensor": {"dtype": "DT_FLOAT", "tensorShape": {"dim": [{"size": "3"}, {"size": "3"}, {"size": "1"}, {"size": "32"}]}}}, "dtype": {"type": "DT_FLOAT"}}}, {"name": "StatefulPartitionedCall/sequential_6/conv2d_22/Conv2D_bn_offset", "op": "Const", "attr": {"dtype": {"type": "DT_FLOAT"}, "value": {"tensor": {"dtype": "DT_FLOAT", "tensorShape": {"dim": [{"size": "32"}]}}}}}, {"name": "StatefulPartitionedCall/sequential_6/conv2d_23/Conv2D_weights", "op": "Const", "attr": {"dtype": {"type": "DT_FLOAT"}, "value": {"tensor": {"dtype": "DT_FLOAT", "tensorShape": {"dim": [{"size": "3"}, {"size": "3"}, {"size": "32"}, {"size": "32"}]}}}}}, {"name": "StatefulPartitionedCall/sequential_6/conv2d_23/Conv2D_bn_offset", "op": "Const", "attr": {"value": {"tensor": {"dtype": "DT_FLOAT", "tensorShape": {"dim": [{"size": "32"}]}}}, "dtype": {"type": "DT_FLOAT"}}}, {"name": "StatefulPartitionedCall/sequential_6/conv2d_24/Conv2D_weights", "op": "Const", "attr": {"dtype": {"type": "DT_FLOAT"}, "value": {"tensor": {"dtype": "DT_FLOAT", "tensorShape": {"dim": [{"size": "3"}, {"size": "3"}, {"size": "32"}, {"size": "64"}]}}}}}, {"name": "StatefulPartitionedCall/sequential_6/conv2d_24/Conv2D_bn_offset", "op": "Const", "attr": {"value": {"tensor": {"dtype": "DT_FLOAT", "tensorShape": {"dim": [{"size": "64"}]}}}, "dtype": {"type": "DT_FLOAT"}}}, {"name": "StatefulPartitionedCall/sequential_6/conv2d_25/Conv2D_weights", "op": "Const", "attr": {"dtype": {"type": "DT_FLOAT"}, "value": {"tensor": {"dtype": "DT_FLOAT", "tensorShape": {"dim": [{"size": "3"}, {"size": "3"}, {"size": "64"}, {"size": "64"}]}}}}}, {"name": "StatefulPartitionedCall/sequential_6/conv2d_25/Conv2D_bn_offset", "op": "Const", "attr": {"value": {"tensor": {"dtype": "DT_FLOAT", "tensorShape": {"dim": [{"size": "64"}]}}}, "dtype": {"type": "DT_FLOAT"}}}, {"name": "StatefulPartitionedCall/sequential_6/activation_30/Relu", "op": "_FusedConv2D", "input": ["conv2d_22_input", "StatefulPartitionedCall/sequential_6/conv2d_22/Conv2D_weights", "StatefulPartitionedCall/sequential_6/conv2d_22/Conv2D_bn_offset"], "device": "/device:CPU:0", "attr": {"explicit_paddings": {"list": {}}, "T": {"type": "DT_FLOAT"}, "fused_ops": {"list": {"s": ["Qmlhc0FkZA==", "UmVsdQ=="]}}, "dilations": {"list": {"i": ["1", "1", "1", "1"]}}, "use_cudnn_on_gpu": {"b": true}, "data_format": {"s": "TkhXQw=="}, "padding": {"s": "VkFMSUQ="}, "num_args": {"i": "1"}, "epsilon": {"f": 0.0}, "strides": {"list": {"i": ["1", "1", "1", "1"]}}}}, {"name": "StatefulPartitionedCall/sequential_6/activation_31/Relu", "op": "_FusedConv2D", "input": ["StatefulPartitionedCall/sequential_6/activation_30/Relu", "StatefulPartitionedCall/sequential_6/conv2d_23/Conv2D_weights", "StatefulPartitionedCall/sequential_6/conv2d_23/Conv2D_bn_offset"], "device": "/device:CPU:0", "attr": {"T": {"type": "DT_FLOAT"}, "use_cudnn_on_gpu": {"b": true}, "padding": {"s": "VkFMSUQ="}, "data_format": {"s": "TkhXQw=="}, "dilations": {"list": {"i": ["1", "1", "1", "1"]}}, "fused_ops": {"list": {"s": ["Qmlhc0FkZA==", "UmVsdQ=="]}}, "strides": {"list": {"i": ["1", "1", "1", "1"]}}, "explicit_paddings": {"list": {}}, "num_args": {"i": "1"}, "epsilon": {"f": 0.0}}}, {"name": "StatefulPartitionedCall/sequential_6/max_pooling2d_12/MaxPool", "op": "MaxPool", "input": ["StatefulPartitionedCall/sequential_6/activation_31/Relu"], "attr": {"explicit_paddings": {"list": {}}, "data_format": {"s": "TkhXQw=="}, "ksize": {"list": {"i": ["1", "2", "2", "1"]}}, "strides": {"list": {"i": ["1", "2", "2", "1"]}}, "T": {"type": "DT_FLOAT"}, "padding": {"s": "VkFMSUQ="}}}, {"name": "StatefulPartitionedCall/sequential_6/activation_32/Relu", "op": "_FusedConv2D", "input": ["StatefulPartitionedCall/sequential_6/max_pooling2d_12/MaxPool", "StatefulPartitionedCall/sequential_6/conv2d_24/Conv2D_weights", "StatefulPartitionedCall/sequential_6/conv2d_24/Conv2D_bn_offset"], "device": "/device:CPU:0", "attr": {"explicit_paddings": {"list": {}}, "num_args": {"i": "1"}, "fused_ops": {"list": {"s": ["Qmlhc0FkZA==", "UmVsdQ=="]}}, "data_format": {"s": "TkhXQw=="}, "T": {"type": "DT_FLOAT"}, "use_cudnn_on_gpu": {"b": true}, "epsilon": {"f": 0.0}, "dilations": {"list": {"i": ["1", "1", "1", "1"]}}, "padding": {"s": "VkFMSUQ="}, "strides": {"list": {"i": ["1", "1", "1", "1"]}}}}, {"name": "StatefulPartitionedCall/sequential_6/activation_33/Relu", "op": "_FusedConv2D", "input": ["StatefulPartitionedCall/sequential_6/activation_32/Relu", "StatefulPartitionedCall/sequential_6/conv2d_25/Conv2D_weights", "StatefulPartitionedCall/sequential_6/conv2d_25/Conv2D_bn_offset"], "device": "/device:CPU:0", "attr": {"dilations": {"list": {"i": ["1", "1", "1", "1"]}}, "strides": {"list": {"i": ["1", "1", "1", "1"]}}, "padding": {"s": "VkFMSUQ="}, "fused_ops": {"list": {"s": ["Qmlhc0FkZA==", "UmVsdQ=="]}}, "use_cudnn_on_gpu": {"b": true}, "T": {"type": "DT_FLOAT"}, "epsilon": {"f": 0.0}, "explicit_paddings": {"list": {}}, "num_args": {"i": "1"}, "data_format": {"s": "TkhXQw=="}}}, {"name": "StatefulPartitionedCall/sequential_6/max_pooling2d_13/MaxPool", "op": "MaxPool", "input": ["StatefulPartitionedCall/sequential_6/activation_33/Relu"], "attr": {"explicit_paddings": {"list": {}}, "data_format": {"s": "TkhXQw=="}, "padding": {"s": "VkFMSUQ="}, "strides": {"list": {"i": ["1", "2", "2", "1"]}}, "ksize": {"list": {"i": ["1", "2", "2", "1"]}}, "T": {"type": "DT_FLOAT"}}}, {"name": "StatefulPartitionedCall/sequential_6/flatten_6/Reshape", "op": "Reshape", "input": ["StatefulPartitionedCall/sequential_6/max_pooling2d_13/MaxPool", "StatefulPartitionedCall/sequential_6/flatten_6/Const"], "attr": {"T": {"type": "DT_FLOAT"}, "Tshape": {"type": "DT_INT32"}}}, {"name": "StatefulPartitionedCall/sequential_6/dense_12/BiasAdd", "op": "_FusedMatMul", "input": ["StatefulPartitionedCall/sequential_6/flatten_6/Reshape", "StatefulPartitionedCall/sequential_6/dense_12/MatMul/ReadVariableOp", "StatefulPartitionedCall/sequential_6/dense_12/BiasAdd/ReadVariableOp"], "device": "/device:CPU:0", "attr": {"T": {"type": "DT_FLOAT"}, "transpose_a": {"b": false}, "fused_ops": {"list": {"s": ["Qmlhc0FkZA=="]}}, "num_args": {"i": "1"}, "transpose_b": {"b": false}, "epsilon": {"f": 0.0}}}, {"name": "StatefulPartitionedCall/sequential_6/batch_normalization_29/batchnorm/mul_1", "op": "Mul", "input": ["StatefulPartitionedCall/sequential_6/dense_12/BiasAdd", "StatefulPartitionedCall/sequential_6/batch_normalization_29/batchnorm/mul"], "attr": {"T": {"type": "DT_FLOAT"}}}, {"name": "StatefulPartitionedCall/sequential_6/batch_normalization_29/batchnorm/add_1", "op": "AddV2", "input": ["StatefulPartitionedCall/sequential_6/batch_normalization_29/batchnorm/mul_1", "StatefulPartitionedCall/sequential_6/batch_normalization_29/batchnorm/sub"], "attr": {"T": {"type": "DT_FLOAT"}}}, {"name": "StatefulPartitionedCall/sequential_6/activation_34/Relu", "op": "Relu", "input": ["StatefulPartitionedCall/sequential_6/batch_normalization_29/batchnorm/add_1"], "attr": {"T": {"type": "DT_FLOAT"}}}, {"name": "StatefulPartitionedCall/sequential_6/dense_13/BiasAdd", "op": "_FusedMatMul", "input": ["StatefulPartitionedCall/sequential_6/activation_34/Relu", "StatefulPartitionedCall/sequential_6/dense_13/MatMul/ReadVariableOp", "StatefulPartitionedCall/sequential_6/dense_13/BiasAdd/ReadVariableOp"], "device": "/device:CPU:0", "attr": {"num_args": {"i": "1"}, "T": {"type": "DT_FLOAT"}, "epsilon": {"f": 0.0}, "fused_ops": {"list": {"s": ["Qmlhc0FkZA=="]}}, "transpose_b": {"b": false}, "transpose_a": {"b": false}}}, {"name": "StatefulPartitionedCall/sequential_6/activation_35/Softmax", "op": "Softmax", "input": ["StatefulPartitionedCall/sequential_6/dense_13/BiasAdd"], "attr": {"T": {"type": "DT_FLOAT"}}}, {"name": "Identity", "op": "Identity", "input": ["StatefulPartitionedCall/sequential_6/activation_35/Softmax"], "attr": {"T": {"type": "DT_FLOAT"}}}], "library": {}, "versions": {"producer": 1087}}, "weightsManifest": [{"paths": ["group1-shard1of1.bin"], "weights": [{"name": "StatefulPartitionedCall/sequential_6/flatten_6/Const", "shape": [2], "dtype": "int32"}, {"name": "StatefulPartitionedCall/sequential_6/dense_12/MatMul/ReadVariableOp", "shape": [1024, 512], "dtype": "float32"}, {"name": "StatefulPartitionedCall/sequential_6/dense_12/BiasAdd/ReadVariableOp", "shape": [512], "dtype": "float32"}, {"name": "StatefulPartitionedCall/sequential_6/batch_normalization_29/batchnorm/mul", "shape": [512], "dtype": "float32"}, {"name": "StatefulPartitionedCall/sequential_6/batch_normalization_29/batchnorm/sub", "shape": [512], "dtype": "float32"}, {"name": "StatefulPartitionedCall/sequential_6/dense_13/MatMul/ReadVariableOp", "shape": [512, 10], "dtype": "float32"}, {"name": "StatefulPartitionedCall/sequential_6/dense_13/BiasAdd/ReadVariableOp", "shape": [10], "dtype": "float32"}, {"name": "StatefulPartitionedCall/sequential_6/conv2d_22/Conv2D_weights", "shape": [3, 3, 1, 32], "dtype": "float32"}, {"name": "StatefulPartitionedCall/sequential_6/conv2d_22/Conv2D_bn_offset", "shape": [32], "dtype": "float32"}, {"name": "StatefulPartitionedCall/sequential_6/conv2d_23/Conv2D_weights", "shape": [3, 3, 32, 32], "dtype": "float32"}, {"name": "StatefulPartitionedCall/sequential_6/conv2d_23/Conv2D_bn_offset", "shape": [32], "dtype": "float32"}, {"name": "StatefulPartitionedCall/sequential_6/conv2d_24/Conv2D_weights", "shape": [3, 3, 32, 64], "dtype": "float32"}, {"name": "StatefulPartitionedCall/sequential_6/conv2d_24/Conv2D_bn_offset", "shape": [64], "dtype": "float32"}, {"name": "StatefulPartitionedCall/sequential_6/conv2d_25/Conv2D_weights", "shape": [3, 3, 64, 64], "dtype": "float32"}, {"name": "StatefulPartitionedCall/sequential_6/conv2d_25/Conv2D_bn_offset", "shape": [64], "dtype": "float32"}]}]}
1 change: 1 addition & 0 deletions tfjs-models/models/fashion/weights.json

Large diffs are not rendered by default.