Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Iainmon committed Jan 13, 2025
2 parents 30e8e17 + 0d66ff0 commit 42fb705
Show file tree
Hide file tree
Showing 22 changed files with 2,434,365 additions and 1 deletion.
50 changes: 50 additions & 0 deletions examples/MNIST_CNN_Interactive_Demo/ProjectDemo.chpl
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);
41 changes: 41 additions & 0 deletions examples/MNIST_CNN_Interactive_Demo/model/0.bias.json
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
]
}
Loading

0 comments on commit 42fb705

Please sign in to comment.