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
from cainvas import cpp2ipynb | |
cpp2ipynb("./asl_model/asl_model.cpp") |
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
import deepC | |
os.makedirs("./asl_model", exist_ok=True) |
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
import onnx | |
onnx_model=onnx.load_model("./asl_model.onnx") | |
# Check that the IR is well formed | |
import caffe2.python.onnx.backend as backend | |
for gesture, lbl in zip(inputs_train, outputs_train) : | |
gesture = gesture.astype(np.float32) | |
onnx.checker.check_model(onnx_model) |
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
dummy_input = torch.randn(INPUT_LEN) | |
torch.onnx.export(model, (dummy_input), "./asl_model.onnx", verbose=True) |
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
evaluate_x = torch.from_numpy(np.array(inputs_train, dtype=np.float32)) | |
evaluate_y = torch.from_numpy(outputs_train) | |
if cuda: | |
evaluate_x, evaluate_y = evaluate_x.cuda(), evaluate_y.cuda() | |
model.eval() | |
output = model(evaluate_x) | |
pred = output.data.max(1)[1] | |
#print(pred) | |
d = pred.eq(evaluate_y.data).cpu() |
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
EPOCHS = 150 | |
for epoch in range(EPOCHS): | |
model.train() | |
running_loss = 0.0 | |
for batch_idx, (data, target) in \ | |
enumerate(zip(inputs_train, np.expand_dims(outputs_train, axis=1))): | |
# Get Samples | |
data = torch.from_numpy(np.array(data, dtype=np.float32)) |
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
class aslModel(nn.Module): | |
def __init__(self): | |
super(aslModel, self).__init__() | |
self.fc1 = nn.Linear(INPUT_LEN, 128) | |
self.fc2 = nn.Linear(128, 16) | |
self.fc3 = nn.Linear(16, NUM_GESTURES) | |
def forward(self, x): | |
x = x.view((-1, INPUT_LEN)) | |
h = F.relu(self.fc1(x)) |
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
# https://stackoverflow.com/a/37710486/2020087 | |
num_inputs = len(inputs) | |
randomize = np.arange(num_inputs) | |
np.random.shuffle(randomize) | |
# Swap the consecutive indexes (0, 1, 2, etc) with the randomized indexes | |
inputs = inputs[randomize] | |
outputs = outputs[randomize] | |
# Split the recordings (group of samples) into three sets: training, testing and validation |
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
# Set a fixed random seed value, for reproducibility, this will allow us to get | |
# the same random numbers each time the notebook is run | |
SEED = 1337 | |
np.random.seed(SEED) | |
cuda = torch.cuda.is_available() | |
torch.manual_seed(SEED) | |
if cuda: | |
torch.cuda.manual_seed(SEED) | |
# the list of gestures |
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
plot_gesture( | |
["https://cainvas-static.s3.amazonaws.com/media/user_data/cainvas-admin/hi.csv", | |
"https://cainvas-static.s3.amazonaws.com/media/user_data/cainvas-admin/sup.csv"], | |
["hi.csv", "sup.csv"], | |
"Gyroscope" | |
) |
NewerOlder