This file contains hidden or 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 sys | |
import json | |
import openai | |
from langchain.text_splitter import Document | |
# ===== Functions ====== | |
def build_prompt(input_docs, user_input): | |
This file contains hidden or 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 tensorflow import keras | |
import tensorflow.keras.backend as K | |
from tensorflow.keras.models import Model | |
from tensorflow.keras.layers import Input, Dense | |
import numpy as np | |
import cv2 | |
import matplotlib | |
import matplotlib.pyplot as plt |
This file contains hidden or 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 onnxruntime as onnxrun | |
# Processing with ONNX Runtime | |
REAL_Prediction = np.array(sess.run(None, {WORD_InputName: REAL_InputVector})) | |
REAL_PredictionConfidence = REAL_Prediction[0, 0, np.argmax(REAL_Prediction)] | |
REAL_PredictionConfidence = round(REAL_PredictionConfidence*100, 2) | |
DINT_ResultVector = np.argmax(REAL_Prediction) |
This file contains hidden or 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 tensorflow import keras | |
import onnxmltools | |
# Load and convert model to ONNX | |
model = keras.models.load_model('model_curvetypes.h5') | |
onnx_model = onnxmltools.convert_keras(model, model.name) | |
onnxmltools.utils.save_model(onnx_model, 'model_curvetypes.onnx') |
This file contains hidden or 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
PROGRAM PLC_PRG | |
VAR | |
BOOL_O_JetsonTrigger : BOOL := FALSE; | |
DINT_Step : DINT := 0; | |
DINT_InputVectorLength : DINT := 20; | |
This file contains hidden or 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
start_preprocessing = time.time() | |
prediction = model.predict(predict_arr) | |
end_preprocessing = time.time() | |
pred_conf = prediction[0, np.argmax(prediction)] | |
pred_conf = round(pred_conf*100, 2) | |
pred_time = round((end_preprocessing-start_preprocessing), 3) | |
print('Predicted class no.: ' + str(np.argmax(prediction))) |
This file contains hidden or 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
# Specific sample | |
#predict_arr = X_test[15].reshape(1,20) | |
#predict_ground_truth = y_onehot_test[15] | |
# Random sample | |
rand_index = np.random.choice(len(X_test), 1) | |
predict_arr = X_test[rand_index].reshape(1,20) | |
predict_ground_truth = y_onehot_test[rand_index] | |
This file contains hidden or 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
def get_model(): | |
model = Sequential() | |
model.add(Dense(64, input_dim=20, activation='relu')) | |
model.add(Dropout(0.2)) | |
model.add(Dense(128, activation='relu')) | |
model.add(Dropout(0.3)) | |
model.add(Dense(32, activation='relu')) | |
model.add(Dropout(0.5)) | |
model.add(Dense(16, activation='relu')) | |
model.add(Dropout(0.5)) |
This file contains hidden or 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
# Split x/y | |
X = data.values[:,0:-1] | |
Y = data.values[:,-1] | |
X = X.astype('float32') | |
# Encode label vector | |
encoder = LabelEncoder() | |
encoded_Y = encoder.fit_transform(Y) |
This file contains hidden or 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
data = pd.read_csv('curve_dataset_train.csv', index_col=False) | |
data = data.sample(frac=1, random_state=42).reset_index() | |
data.drop(['index'], 1, inplace=True) | |
print(data.shape) | |
data[:9][['shape', 'x1', 'y1','x2', 'y2','x3', 'y3','x4', 'y4','x5', 'y5','x6', 'y6','x7', 'y7','x8', 'y8','x9', 'y9','x10', 'y10']] |
NewerOlder