forked from huaweicloud/ModelArts-Lab
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update caffe case (huaweicloud#1709)
* Delete train.py * Delete lenet_train_test.prototxt * Delete lenet_solver.prototxt * Create README.md * Add files via upload * Delete README.md * Add files via upload
- Loading branch information
1 parent
9dce718
commit d1e8dca
Showing
7 changed files
with
323 additions
and
109 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
..._examples/Using_Caffe_to_Create_a_MNIST_Dataset_Recognition_Application/codes/config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"apis": [{"url": "/", "request": {"Content-type": "multipart/form-data", "data": {"type": "object", "properties": {"images": {"type": "file"}}}}, "protocol": "http", "method": "post", "response": {"Content-type": "multipart/form-data", "data": {"required": ["predicted_label", "scores"], "type": "object", "properties": {"predicted_label": {"type": "string"}, "scores": {"items": {"minItems": 2, "items": [{"type": "string"}, {"type": "number"}], "type": "array", "maxItems": 2}, "type": "array"}}}}}], "service_name": "builtin_algorithms", "model_algorithm": "image_classification", "metrics": {"f1": 1.0, "accuracy": 1.0, "precision": 1.0, "recall": 1.0}, "tunable": false, "model_source": "algos", "model_type": "Caffe"} |
33 changes: 33 additions & 0 deletions
33
.../Using_Caffe_to_Create_a_MNIST_Dataset_Recognition_Application/codes/customize_service.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import caffe | ||
from model_service.caffe_model_service import CaffeBaseService | ||
LABELS = {'0': '0', '1': '1', '2': '2', '3': '3', '4': '4', | ||
'5': '5', '6': '6', '7': '7', '8': '8', '9': '9'} | ||
|
||
class ResnetService(CaffeBaseService): | ||
|
||
def __init__(self, model_name, model_path): | ||
super(ResnetService, self).__init__(model_name, model_path) | ||
# load input and configure preprocessing | ||
transformer = caffe.io.Transformer({'data': self.net.blobs['data'].data.shape}) | ||
transformer.set_transpose('data', (2, 0, 1)) | ||
self.transformer = transformer | ||
self.num_classes = len(LABELS) | ||
|
||
def _preprocess(self, data): | ||
for _, v in data.items(): | ||
for _, file_content in v.items(): | ||
im = caffe.io.load_image(file_content, color=False) | ||
self.net.blobs['data'].data[...] = self.transformer.preprocess('data', im) | ||
return | ||
|
||
def _postprocess(self, data): | ||
data = self.net.blobs['prob'].data[0] | ||
end_idx = -6 if self.num_classes >= 5 else -self.num_classes - 1 | ||
top_k = data.argsort()[-1:end_idx:-1] | ||
print(top_k) | ||
return { | ||
"predicted_label": | ||
LABELS[str(top_k[0])], | ||
"scores": | ||
[[LABELS[str(idx)], float(data[idx])] for idx in top_k] | ||
} |
139 changes: 139 additions & 0 deletions
139
...Using_Caffe_to_Create_a_MNIST_Dataset_Recognition_Application/codes/lenet_deploy.prototxt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
name: "LeNet" | ||
layer { | ||
name: "mnist" | ||
type: "Input" | ||
top: "data" | ||
transform_param { | ||
scale: 0.00390625 | ||
} | ||
input_param { | ||
shape { | ||
dim: 1 | ||
dim: 1 | ||
dim: 28 | ||
dim: 28 | ||
} | ||
} | ||
} | ||
layer { | ||
name: "conv1" | ||
type: "Convolution" | ||
bottom: "data" | ||
top: "conv1" | ||
param { | ||
lr_mult: 1 | ||
} | ||
param { | ||
lr_mult: 2 | ||
} | ||
convolution_param { | ||
num_output: 20 | ||
kernel_size: 5 | ||
stride: 1 | ||
weight_filler { | ||
type: "xavier" | ||
} | ||
bias_filler { | ||
type: "constant" | ||
} | ||
} | ||
} | ||
layer { | ||
name: "pool1" | ||
type: "Pooling" | ||
bottom: "conv1" | ||
top: "pool1" | ||
pooling_param { | ||
pool: MAX | ||
kernel_size: 2 | ||
stride: 2 | ||
} | ||
} | ||
layer { | ||
name: "conv2" | ||
type: "Convolution" | ||
bottom: "pool1" | ||
top: "conv2" | ||
param { | ||
lr_mult: 1 | ||
} | ||
param { | ||
lr_mult: 2 | ||
} | ||
convolution_param { | ||
num_output: 50 | ||
kernel_size: 5 | ||
stride: 1 | ||
weight_filler { | ||
type: "xavier" | ||
} | ||
bias_filler { | ||
type: "constant" | ||
} | ||
} | ||
} | ||
layer { | ||
name: "pool2" | ||
type: "Pooling" | ||
bottom: "conv2" | ||
top: "pool2" | ||
pooling_param { | ||
pool: MAX | ||
kernel_size: 2 | ||
stride: 2 | ||
} | ||
} | ||
layer { | ||
name: "ip1" | ||
type: "InnerProduct" | ||
bottom: "pool2" | ||
top: "ip1" | ||
param { | ||
lr_mult: 1 | ||
} | ||
param { | ||
lr_mult: 2 | ||
} | ||
inner_product_param { | ||
num_output: 500 | ||
weight_filler { | ||
type: "xavier" | ||
} | ||
bias_filler { | ||
type: "constant" | ||
} | ||
} | ||
} | ||
layer { | ||
name: "relu1" | ||
type: "ReLU" | ||
bottom: "ip1" | ||
top: "ip1" | ||
} | ||
layer { | ||
name: "ip2" | ||
type: "InnerProduct" | ||
bottom: "ip1" | ||
top: "ip2" | ||
param { | ||
lr_mult: 1 | ||
} | ||
param { | ||
lr_mult: 2 | ||
} | ||
inner_product_param { | ||
num_output: 10 | ||
weight_filler { | ||
type: "xavier" | ||
} | ||
bias_filler { | ||
type: "constant" | ||
} | ||
} | ||
} | ||
layer { | ||
name: "prob" | ||
type: "Softmax" | ||
bottom: "ip2" | ||
top: "prob" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 0 additions & 105 deletions
105
...ial_examples/Using_Caffe_to_Create_a_MNIST_Dataset_Recognition_Application/codes/train.py
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.