forked from FEC-SIH-23/Blind-FEC-Extractor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
80 lines (62 loc) · 2.36 KB
/
Copy pathmain.py
File metadata and controls
80 lines (62 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# This Python file uses the following encoding: utf-8
import sys
from pathlib import Path
import asyncio
from PySide6.QtGui import QGuiApplication
from PySide6.QtQml import QQmlApplicationEngine
from PySide6.QtCore import QObject, Slot, Property, Signal
import tensorflow as tf
import pandas as pd
import numpy as np
import tensorflow as tf
from tensorflow.keras.models import load_model
fecEncoding = ['Turbo','Convolutional','LDPC','BCH']
model_path = 'model'
loaded_model = load_model(model_path)
class MyObject(QObject):
messageChanged = Signal(str)
def __init__(self):
QObject.__init__(self)
self._message = ""
@Slot(str, int)
def predict(self, message, flag):
# print(message)
if (flag == 0):
asyncio.run(self.modelOutputWithMessage(message))
else:
asyncio.run(self.modelOutputWithPath(message))
async def modelOutputWithMessage(self, bit_string):
bit_string = bit_string.replace('\n', '')
bit_array = np.array(list(bit_string), dtype=int)
df_test = np.reshape(bit_array, (1, 2048, 1))
df_float = tf.convert_to_tensor(df_test, dtype=tf.float32)
predictions = loaded_model.predict(df_float)
print(predictions)
final = np.argmax(predictions)
print(fecEncoding[final])
self.messageChanged.emit(fecEncoding[final])
async def modelOutputWithPath(self, path):
path.replace("file://", "")
df = pd.read_csv(path)
data = []
for bit_string in df:
bit_array = np.array(list(bit_string), dtype=int)
data.append(bit_array)
df_test = np.reshape(bit_array, (1, 2048, 1))
df_float = tf.convert_to_tensor(df_test, dtype=tf.float32)
predictions = loaded_model.predict(df_float)
print(predictions)
final = np.argmax(predictions)
print(fecEncoding[final])
self.messageChanged.emit(fecEncoding[final])
if __name__ == "__main__":
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
my_object = MyObject()
engine.rootContext().setContextProperty("myObject", my_object)
qml_file = Path(__file__).resolve().parent / "main.qml"
engine.load(qml_file)
if not engine.rootObjects():
sys.exit(-1)
sys.exit(app.exec())
# a slot for a qml signal for a function printing hello world