Skip to content

Instantly share code, notes, and snippets.

View ph_model.py
model = models.Sequential([
layers.Dense(128, activation = 'relu', input_shape = Xtrain[0].shape),
layers.Dense(64, activation = 'relu'),
#layers.Dense(16, activation = 'relu'),
layers.Dense(8, activation = 'relu'),
layers.Dense(1)
])
cb = callbacks.EarlyStopping(patience = 10, restore_best_weights = True)
View ph_split.py
# Splitting into train, val and test set -- 80-10-10 split
# First, an 80-20 split
train_df, val_test_df = train_test_split(df, test_size = 0.2)
# Then split the 20% into half
val_df, test_df = train_test_split(val_test_df, test_size = 0.5)
# Splitting into X (input) and y (output)
View ph_input_output_columns.py
# defining the input and output columns to separate the dataset in the later cells.
input_columns = df.columns.tolist()
input_columns.remove('label')
output_columns = ['label']
View ph_normalization.py
df[['red','green','blue']] /= 255
View muscle_gesture_prediction.py
# pick random test data sample from one batch
x = random.randint(0, len(Xtest) - 1)
output = model.predict(Xtest[x].reshape(1, -1))[0]
pred = np.argmax(output)
print("Predicted: ", pred, "(", output[pred], ")")
print("True: ", np.argmax(np.array(ytest)[x]))
View muscle_gesture_model.py
model = models.Sequential([
layers.Dense(256, activation = 'relu', input_shape = Xtrain[0].shape),
layers.Dense(64, activation = 'relu'),
layers.Dense(16, activation = 'relu'),
layers.Dense(4, activation = 'softmax')
])
cb = [callbacks.EarlyStopping(patience = 5, restore_best_weights = True)]
model.compile(optimizer=optimizers.Adam(0.0001), loss=losses.CategoricalCrossentropy(), metrics=['accuracy'])
View muscle_gesture_stdz.py
ss_scaler = StandardScaler()
# Fit on training set alone
Xtrain = ss_scaler.fit_transform(Xtrain)
# Use it to transform val and test input
Xval = ss_scaler.transform(Xval)
Xtest = ss_scaler.transform(Xtest)
View muscle_gesture_split.py
# Splitting into train, val and test set -- 80-10-10 split
# First, an 80-20 split
Xtrain, Xvaltest, ytrain, yvaltest = train_test_split(X, y, test_size = 0.2)
# Then split the 20% into half
Xval, Xtest, yval, ytest = train_test_split(Xvaltest, yvaltest, test_size = 0.5)
View muscle_gesture_input_output.py
# Input attributes (every column except the last)
X = df[df.columns.tolist()[:-1]]
# Output attribute - one-hot encoded
y = pd.get_dummies(df[64])
View muscle_gesture_load_dataset.py
df0 = pd.read_csv('https://cainvas-static.s3.amazonaws.com/media/user_data/AyishaR0/0.csv', header = None)
df1 = pd.read_csv('https://cainvas-static.s3.amazonaws.com/media/user_data/AyishaR0/1.csv', header = None)
df2 = pd.read_csv('https://cainvas-static.s3.amazonaws.com/media/user_data/AyishaR0/2.csv', header = None)
df3 = pd.read_csv('https://cainvas-static.s3.amazonaws.com/media/user_data/AyishaR0/3.csv', header = None)
df = pd.concat([df0, df1, df2, df3])