-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main'
- Loading branch information
Showing
22 changed files
with
2,434,365 additions
and
1 deletion.
There are no files selected for viewing
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,50 @@ | ||
use Tensor; | ||
|
||
use Network; | ||
|
||
import Time; | ||
|
||
import Image; | ||
|
||
config const detach = true; | ||
|
||
config const weightsFolder = "model/"; | ||
config const specFile = "model/specification.json"; | ||
config const imagePath = "number.png"; | ||
|
||
var img_ = Image.readImage(imagePath, Image.imageType.png); | ||
var img = [i in img_.domain] img_[i] : real(32); | ||
|
||
|
||
Tensor.detachMode(detach); | ||
|
||
// Construct the model from specification. | ||
var model: owned Module(real(32)) = loadModel(specFile=specFile, | ||
weightsFolder=weightsFolder, | ||
dtype=real(32)); | ||
// Print the model's structure. | ||
writeln(model.signature); | ||
|
||
// Load the weights into the model. | ||
model.loadPyTorchDump(weightsFolder); | ||
|
||
var imagend = new ndarray(img); | ||
|
||
// writeln(imagend.shape); | ||
|
||
var image = new dynamicTensor(imagend.reshape(1,28,28)); | ||
|
||
// Create array of output results. | ||
|
||
writeln("started"); | ||
config const numTimes = 1; | ||
var st = new Time.stopwatch(); | ||
st.start(); | ||
const pred = model(image).argmax(); | ||
st.stop(); | ||
|
||
const time = st.elapsed(); | ||
writeln("Time: ", time, " seconds."); | ||
|
||
|
||
writeln("I think it's a ", pred); |
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,41 @@ | ||
{ | ||
"rank": 1, | ||
"shape": [ | ||
32 | ||
], | ||
"dtype": "float64", | ||
"data": [ | ||
-0.12343578040599823, | ||
0.06212015450000763, | ||
-0.029010584577918053, | ||
-0.16593652963638306, | ||
0.02885451167821884, | ||
0.10515154153108597, | ||
-0.13995109498500824, | ||
-0.10198166221380234, | ||
-0.14802095293998718, | ||
0.04423534497618675, | ||
-0.15120548009872437, | ||
-0.21409626305103302, | ||
-0.16688412427902222, | ||
-0.18294550478458405, | ||
-0.11644219607114792, | ||
-0.07498931139707565, | ||
-0.20663811266422272, | ||
-0.14019237458705902, | ||
-0.15334303677082062, | ||
0.07354093343019485, | ||
-0.043126024305820465, | ||
0.16986769437789917, | ||
-0.09064149856567383, | ||
-0.1610468178987503, | ||
-0.2019568383693695, | ||
-0.25095441937446594, | ||
0.10429887473583221, | ||
-0.19952405989170074, | ||
-0.15713489055633545, | ||
0.10607622563838959, | ||
0.18707863986492157, | ||
-0.07820728421211243 | ||
] | ||
} |
Oops, something went wrong.