onlyone2019
commited on
Commit
•
98a04ae
1
Parent(s):
03bb099
add config.json
Browse files- .idea/.gitignore +0 -0
- .idea/inspectionProfiles/Project_Default.xml +15 -0
- .idea/inspectionProfiles/profiles_settings.xml +6 -0
- .idea/misc.xml +4 -0
- .idea/mnist-torch.iml +8 -0
- .idea/modules.xml +8 -0
- .idea/vcs.xml +6 -0
- .idea/workspace.xml +39 -0
- Model.py +0 -20
- config.json +49 -0
- inference.py +0 -29
- mnist.pkl → pytorch_model.bin +2 -2
.idea/.gitignore
ADDED
File without changes
|
.idea/inspectionProfiles/Project_Default.xml
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<component name="InspectionProjectProfileManager">
|
2 |
+
<profile version="1.0">
|
3 |
+
<option name="myName" value="Project Default" />
|
4 |
+
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
5 |
+
<option name="ignoredPackages">
|
6 |
+
<value>
|
7 |
+
<list size="2">
|
8 |
+
<item index="0" class="java.lang.String" itemvalue="opencv-python" />
|
9 |
+
<item index="1" class="java.lang.String" itemvalue="opencv-python-headless" />
|
10 |
+
</list>
|
11 |
+
</value>
|
12 |
+
</option>
|
13 |
+
</inspection_tool>
|
14 |
+
</profile>
|
15 |
+
</component>
|
.idea/inspectionProfiles/profiles_settings.xml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<component name="InspectionProjectProfileManager">
|
2 |
+
<settings>
|
3 |
+
<option name="USE_PROJECT_PROFILE" value="false" />
|
4 |
+
<version value="1.0" />
|
5 |
+
</settings>
|
6 |
+
</component>
|
.idea/misc.xml
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
|
4 |
+
</project>
|
.idea/mnist-torch.iml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<module type="PYTHON_MODULE" version="4">
|
3 |
+
<component name="NewModuleRootManager">
|
4 |
+
<content url="file://$MODULE_DIR$" />
|
5 |
+
<orderEntry type="inheritedJdk" />
|
6 |
+
<orderEntry type="sourceFolder" forTests="false" />
|
7 |
+
</component>
|
8 |
+
</module>
|
.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="ProjectModuleManager">
|
4 |
+
<modules>
|
5 |
+
<module fileurl="file://$PROJECT_DIR$/.idea/mnist-torch.iml" filepath="$PROJECT_DIR$/.idea/mnist-torch.iml" />
|
6 |
+
</modules>
|
7 |
+
</component>
|
8 |
+
</project>
|
.idea/vcs.xml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="VcsDirectoryMappings">
|
4 |
+
<mapping directory="" vcs="Git" />
|
5 |
+
</component>
|
6 |
+
</project>
|
.idea/workspace.xml
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="ChangeListManager">
|
4 |
+
<list default="true" id="496dc987-855c-4173-8d76-bd94b776a63a" name="Changes" comment="" />
|
5 |
+
<option name="SHOW_DIALOG" value="false" />
|
6 |
+
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
7 |
+
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
8 |
+
<option name="LAST_RESOLUTION" value="IGNORE" />
|
9 |
+
</component>
|
10 |
+
<component name="Git.Settings">
|
11 |
+
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
12 |
+
</component>
|
13 |
+
<component name="MarkdownSettingsMigration">
|
14 |
+
<option name="stateVersion" value="1" />
|
15 |
+
</component>
|
16 |
+
<component name="ProjectId" id="2Os1vawLggIVe2m7oXHeWPnayFD" />
|
17 |
+
<component name="ProjectViewState">
|
18 |
+
<option name="hideEmptyMiddlePackages" value="true" />
|
19 |
+
<option name="showLibraryContents" value="true" />
|
20 |
+
</component>
|
21 |
+
<component name="PropertiesComponent"><![CDATA[{
|
22 |
+
"keyToString": {
|
23 |
+
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
24 |
+
"RunOnceActivity.ShowReadmeOnStart": "true",
|
25 |
+
"last_opened_file_path": "/home/wangjie/modelServing/huggingface/chatglm"
|
26 |
+
}
|
27 |
+
}]]></component>
|
28 |
+
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
29 |
+
<component name="TaskManager">
|
30 |
+
<task active="true" id="Default" summary="Default task">
|
31 |
+
<changelist id="496dc987-855c-4173-8d76-bd94b776a63a" name="Changes" comment="" />
|
32 |
+
<created>1682334706298</created>
|
33 |
+
<option name="number" value="Default" />
|
34 |
+
<option name="presentableId" value="Default" />
|
35 |
+
<updated>1682334706298</updated>
|
36 |
+
</task>
|
37 |
+
<servers />
|
38 |
+
</component>
|
39 |
+
</project>
|
Model.py
DELETED
@@ -1,20 +0,0 @@
|
|
1 |
-
import torch
|
2 |
-
|
3 |
-
class MNIST(torch.nn.Module):
|
4 |
-
def __init__(self):
|
5 |
-
super(MNIST, self).__init__()
|
6 |
-
self.conv = torch.nn.Sequential(torch.nn.Conv2d(1, 32, 3, 1, 1),
|
7 |
-
torch.nn.ReLU(),
|
8 |
-
torch.nn.Conv2d(32, 64, 3, 1, 1),
|
9 |
-
torch.nn.ReLU(),
|
10 |
-
torch.nn.MaxPool2d(2, 2))
|
11 |
-
self.dense = torch.nn.Sequential(torch.nn.Linear(14 * 14 * 64, 1024),
|
12 |
-
torch.nn.ReLU(),
|
13 |
-
torch.nn.Dropout(p=0.2),
|
14 |
-
torch.nn.Linear(1024, 10))
|
15 |
-
|
16 |
-
def forward(self, x):
|
17 |
-
x = self.conv(x)
|
18 |
-
x = x.view(-1, 14 * 14 * 64)
|
19 |
-
x = self.dense(x)
|
20 |
-
return x
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config.json
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "google/vit-base-patch16-224-in21k",
|
3 |
+
"architectures": [
|
4 |
+
"ViTForImageClassification"
|
5 |
+
],
|
6 |
+
"attention_probs_dropout_prob": 0.0,
|
7 |
+
"encoder_stride": 16,
|
8 |
+
"finetuning_task": "image-classification",
|
9 |
+
"hidden_act": "gelu",
|
10 |
+
"hidden_dropout_prob": 0.0,
|
11 |
+
"hidden_size": 768,
|
12 |
+
"id2label": {
|
13 |
+
"0": "0",
|
14 |
+
"1": "1",
|
15 |
+
"2": "2",
|
16 |
+
"3": "3",
|
17 |
+
"4": "4",
|
18 |
+
"5": "5",
|
19 |
+
"6": "6",
|
20 |
+
"7": "7",
|
21 |
+
"8": "8",
|
22 |
+
"9": "9"
|
23 |
+
},
|
24 |
+
"image_size": 224,
|
25 |
+
"initializer_range": 0.02,
|
26 |
+
"intermediate_size": 3072,
|
27 |
+
"label2id": {
|
28 |
+
"0": "0",
|
29 |
+
"1": "1",
|
30 |
+
"2": "2",
|
31 |
+
"3": "3",
|
32 |
+
"4": "4",
|
33 |
+
"5": "5",
|
34 |
+
"6": "6",
|
35 |
+
"7": "7",
|
36 |
+
"8": "8",
|
37 |
+
"9": "9"
|
38 |
+
},
|
39 |
+
"layer_norm_eps": 1e-12,
|
40 |
+
"model_type": "vit",
|
41 |
+
"num_attention_heads": 12,
|
42 |
+
"num_channels": 3,
|
43 |
+
"num_hidden_layers": 12,
|
44 |
+
"patch_size": 16,
|
45 |
+
"problem_type": "single_label_classification",
|
46 |
+
"qkv_bias": true,
|
47 |
+
"torch_dtype": "float32",
|
48 |
+
"transformers_version": "4.22.0.dev0"
|
49 |
+
}
|
inference.py
DELETED
@@ -1,29 +0,0 @@
|
|
1 |
-
import cv2
|
2 |
-
import torch
|
3 |
-
from torchvision import datasets, transforms
|
4 |
-
import time
|
5 |
-
from Model import MNIST
|
6 |
-
import numpy
|
7 |
-
# from torch.utils.data import DataLoader
|
8 |
-
def images2tensor(image):
|
9 |
-
img = cv2.imread(image)
|
10 |
-
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
11 |
-
transf = transforms.ToTensor()
|
12 |
-
img_tensor = torch.unsqueeze(transf(img), dim=0)
|
13 |
-
return img_tensor
|
14 |
-
|
15 |
-
|
16 |
-
if __name__ == "__main__":
|
17 |
-
device = torch.device('cpu')
|
18 |
-
model = MNIST().to(device)
|
19 |
-
model.load_state_dict(torch.load('mnist.pkl' , map_location=device)) # load
|
20 |
-
# test_dataset = datasets.MNIST(root='data/', train=False, transform=transforms.ToTensor(), download=True)
|
21 |
-
# test_image , l = test_dataset[0]
|
22 |
-
input_data = images2tensor("0.png")
|
23 |
-
start = time.time()
|
24 |
-
res = model(input_data)
|
25 |
-
end = time.time()
|
26 |
-
res = res.detach().numpy()
|
27 |
-
# res = numpy.array(res)
|
28 |
-
print("手写数å—图片检测的结果为:", res.argmax())
|
29 |
-
# print("infer time: ", end - start)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mnist.pkl → pytorch_model.bin
RENAMED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:354112314c2a6a219b585b09197af8a67b09d110ba53b09d8cfdf8a93a2bbf1c
|
3 |
+
size 343291569
|