Views
No views yet
1import numpy as np
2import pandas as pd
3from sklearn.preprocessing import StandardScaler
4from tensorflow.keras.models import load_model
5import matplotlib.pyplot as plt
6
7model_path = 'model-yolu'
8
9model = load_model(model_path)
10
11model_name = model_path.split('/')[-1].split('.')[0]
12
13plt.figure(figsize=(10, 6))
14plt.title(f'Duygu Tahmini ({model_name})')
15plt.xlabel('Zaman')
16plt.ylabel('Sınıf')
17plt.legend(loc='upper right')
18plt.grid(True)
19plt.show()
20model.summary()1import numpy as np
2import pandas as pd
3from sklearn.preprocessing import StandardScaler
4from tensorflow.keras.models import load_model
5
6model_path = 'model-yolu'
7
8model = load_model(model_path)
9
10scaler = StandardScaler()
11
12predictions = model.predict(X_new_reshaped)
13predicted_labels = np.argmax(predictions, axis=1)
14
15label_mapping = {'NEGATIVE': 0, 'NEUTRAL': 1, 'POSITIVE': 2}
16label_mapping_reverse = {v: k for k, v in label_mapping.items()}
17
18#new_input = np.array([[23, 465, 12, 9653] * 637])
19new_input = np.random.rand(1, 2548) # 1 örnek ve 2548 özellik
20new_input_scaled = scaler.fit_transform(new_input)
21new_input_reshaped = new_input_scaled.reshape((new_input_scaled.shape[0], 1, new_input_scaled.shape[1]))
22
23new_prediction = model.predict(new_input_reshaped)
24predicted_label = np.argmax(new_prediction, axis=1)[0]
25predicted_emotion = label_mapping_reverse[predicted_label]
26
27# TR Lang
28if predicted_emotion == 'NEGATIVE':
29 predicted_emotion = 'Negatif'
30elif predicted_emotion == 'NEUTRAL':
31 predicted_emotion = 'Nötr'
32elif predicted_emotion == 'POSITIVE':
33 predicted_emotion = 'Pozitif'
34
35print(f'Girilen Veri: {new_input}')
36print(f'Tahmin Edilen Duygu: {predicted_emotion}')1import sys
2import pyaudio
3import numpy as np
4import matplotlib.pyplot as plt
5from matplotlib.lines import Line2D
6from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QVBoxLayout, QWidget
7from PyQt5.QtCore import QTimer
8from PyQt5.QtGui import QIcon
9from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
10from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
11
12
13CHUNK = 1000 # Chunk size
14FORMAT = pyaudio.paInt16 # Data type (16-bit PCM)
15CHANNELS = 1 # (Mono)
16RATE = 2000 # Sample rate (Hz)
17
18p = pyaudio.PyAudio()
19
20stream = p.open(format=FORMAT,
21 channels=CHANNELS,
22 rate=RATE,
23 input=True,
24 frames_per_buffer=CHUNK)
25
26
27class MainWindow(QMainWindow):
28 def __init__(self):
29 super().__init__()
30
31 self.initUI()
32
33 self.timer = QTimer()
34 self.timer.timeout.connect(self.update_plot)
35 self.timer.start(1)
36
37 def initUI(self):
38 self.setWindowTitle('EEG Monitoring by Neurazum')
39 self.setWindowIcon(QIcon('/neurazumicon.ico'))
40
41 self.central_widget = QWidget()
42 self.setCentralWidget(self.central_widget)
43
44 self.layout = QVBoxLayout(self.central_widget)
45
46 self.fig, (self.ax1, self.ax2) = plt.subplots(2, 1, figsize=(12, 8), gridspec_kw={'height_ratios': [9, 1]})
47 self.fig.tight_layout()
48 self.canvas = FigureCanvas(self.fig)
49
50 self.layout.addWidget(self.canvas)
51
52 self.toolbar = NavigationToolbar(self.canvas, self)
53 self.layout.addWidget(self.toolbar)
54
55 self.x = np.arange(0, 2 * CHUNK, 2)
56 self.line1, = self.ax1.plot(self.x, np.random.rand(CHUNK))
57 self.line2, = self.ax2.plot(self.x, np.random.rand(CHUNK))
58
59 self.legend_elements = [
60 Line2D([0, 4], [0], color='yellow', lw=4, label='DELTA (0hz-4hz)'),
61 Line2D([4, 7], [0], color='blue', lw=4, label='TETA (4hz-7hz)'),
62 Line2D([8, 12], [0], color='green', lw=4, label='ALFA (8hz-12hz)'),
63 Line2D([12, 30], [0], color='red', lw=4, label='BETA (12hz-30hz)'),
64 Line2D([30, 100], [0], color='purple', lw=4, label='GAMA (30hz-100hz)')
65 ]
66
67 def update_plot(self):
68 data = np.frombuffer(stream.read(CHUNK), dtype=np.int16)
69 data = np.abs(data)
70 voltage_data = data * (3.3 / 1024) # Voltajı "mV"'ye dönüştürme
71 frequency = voltage_data / (RATE * 1000) # Frekans hesaplama
72
73 self.line1.set_ydata(data)
74 self.line2.set_ydata(frequency)
75
76 for coll in self.ax1.collections:
77 coll.remove()
78
79 self.ax1.fill_between(self.x, data, where=((self.x >= 0) & (self.x <= 4)), color='yellow', alpha=1)
80 self.ax1.fill_between(self.x, data, where=((self.x >= 4) & (self.x <= 7)), color='blue', alpha=1)
81 self.ax1.fill_between(self.x, data, where=((self.x >= 8) & (self.x <= 12)), color='green', alpha=1)
82 self.ax1.fill_between(self.x, data, where=((self.x >= 12) & (self.x <= 30)), color='red', alpha=1)
83 self.ax1.fill_between(self.x, data, where=((self.x >= 30) & (self.x <= 100)), color='purple', alpha=1)
84
85 self.ax1.legend(handles=self.legend_elements, loc='upper right')
86 self.ax1.set_ylabel('Genlik (uV)')
87 self.ax1.set_xlabel('Frekans (Hz)')
88 self.ax1.set_title('Frekans ve Genlik Değerleri')
89
90 self.ax2.set_ylabel('Voltaj (mV)')
91 self.ax2.set_xlabel('Zaman')
92
93 self.canvas.draw()
94
95 def close_application(self):
96 self.timer.stop()
97 stream.stop_stream()
98 stream.close()
99 p.terminate()
100 sys.exit(app.exec_())
101
102
103if __name__ == '__main__':
104 app = QApplication(sys.argv)
105 mainWin = MainWindow()
106 mainWin.show()
107 sys.exit(app.exec_())1import numpy as np
2import pandas as pd
3from sklearn.preprocessing import StandardScaler
4from tensorflow.keras.models import load_model
5
6model_path = 'model-yolu'
7new_data_path = 'veri-seti-yolu'
8
9model = load_model(model_path)
10
11new_data = pd.read_csv(new_data_path)
12
13X_new = new_data.drop('label', axis=1)
14y_new = new_data['label']
15
16scaler = StandardScaler()
17X_new_scaled = scaler.fit_transform(X_new)
18X_new_reshaped = X_new_scaled.reshape((X_new_scaled.shape[0], 1, X_new_scaled.shape[1]))
19
20predictions = model.predict(X_new_reshaped)
21predicted_labels = np.argmax(predictions, axis=1)
22
23label_mapping = {'NEGATIVE': 0, 'NEUTRAL': 1, 'POSITIVE': 2}
24label_mapping_reverse = {v: k for k, v in label_mapping.items()}
25actual_labels = y_new.replace(label_mapping).values
26
27accuracy = np.mean(predicted_labels == actual_labels)
28
29new_input = np.random.rand(2548, 2548) # 1 örnek ve 2548 özellik
30new_input_scaled = scaler.transform(new_input)
31new_input_reshaped = new_input_scaled.reshape((new_input_scaled.shape[0], 1, new_input_scaled.shape[1]))
32
33new_prediction = model.predict(new_input_reshaped)
34predicted_label = np.argmax(new_prediction, axis=1)[0]
35predicted_emotion = label_mapping_reverse[predicted_label]
36
37
38# TR Lang
39if predicted_emotion == 'NEGATIVE':
40 predicted_emotion = 'Negatif'
41elif predicted_emotion == 'NEUTRAL':
42 predicted_emotion = 'Nötr'
43elif predicted_emotion == 'POSITIVE':
44 predicted_emotion = 'Pozitif'
45
46print(f'Giriş Verisi: {new_input}')
47print(f'Tahmin Edilen Duygu: {predicted_emotion}')
48print(f'Doğruluk: %{accuracy * 100:.5f}')pip install -r requirements.txt1import numpy as np
2import pandas as pd
3from sklearn.preprocessing import StandardScaler
4from tensorflow.keras.models import load_model
5import matplotlib.pyplot as plt
6
7model_path = 'model-path'
8
9model = load_model(model_path)
10
11model_name = model_path.split('/')[-1].split('.')[0]
12
13plt.figure(figsize=(10, 6))
14plt.title(f'Emotion Prediction ({model_name})')
15plt.xlabel('Time')
16plt.ylabel('Class')
17plt.legend(loc='upper right')
18plt.grid(True)
19plt.show()
20model.summary()1import numpy as np
2import pandas as pd
3from sklearn.preprocessing import StandardScaler
4from tensorflow.keras.models import load_model
5
6model_path = 'model-path'
7
8model = load_model(model_path)
9
10scaler = StandardScaler()
11
12predictions = model.predict(X_new_reshaped)
13predicted_labels = np.argmax(predictions, axis=1)
14
15label_mapping = {'NEGATIVE': 0, 'NEUTRAL': 1, 'POSITIVE': 2}
16label_mapping_reverse = {v: k for k, v in label_mapping.items()}
17
18#new_input = np.array([[23, 465, 12, 9653] * 637])
19new_input = np.random.rand(1, 2548) # 1 sample and 2548 features
20new_input_scaled = scaler.fit_transform(new_input)
21new_input_reshaped = new_input_scaled.reshape((new_input_scaled.shape[0], 1, new_input_scaled.shape[1]))
22
23new_prediction = model.predict(new_input_reshaped)
24predicted_label = np.argmax(new_prediction, axis=1)[0]
25predicted_emotion = label_mapping_reverse[predicted_label]
26
27# TR Lang
28if predicted_emotion == 'NEGATIVE':
29 predicted_emotion = 'Negatif'
30elif predicted_emotion == 'NEUTRAL':
31 predicted_emotion = 'Nötr'
32elif predicted_emotion == 'POSITIVE':
33 predicted_emotion = 'Pozitif'
34
35print(f'Input Data: {new_input}')
36print(f'Predicted Emotion: {predicted_emotion}')1import sys
2import pyaudio
3import numpy as np
4import matplotlib.pyplot as plt
5from matplotlib.lines import Line2D
6from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QVBoxLayout, QWidget
7from PyQt5.QtCore import QTimer
8from PyQt5.QtGui import QIcon
9from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
10from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
11
12
13CHUNK = 1000 # Chunk size
14FORMAT = pyaudio.paInt16 # Data type (16-bit PCM)
15CHANNELS = 1 # (Mono)
16RATE = 2000 # Sample rate (Hz)
17
18p = pyaudio.PyAudio()
19
20stream = p.open(format=FORMAT,
21 channels=CHANNELS,
22 rate=RATE,
23 input=True,
24 frames_per_buffer=CHUNK)
25
26
27class MainWindow(QMainWindow):
28 def __init__(self):
29 super().__init__()
30
31 self.initUI()
32
33 self.timer = QTimer()
34 self.timer.timeout.connect(self.update_plot)
35 self.timer.start(1)
36
37 def initUI(self):
38 self.setWindowTitle('EEG Monitoring by Neurazum')
39 self.setWindowIcon(QIcon('/neurazumicon.ico'))
40
41 self.central_widget = QWidget()
42 self.setCentralWidget(self.central_widget)
43
44 self.layout = QVBoxLayout(self.central_widget)
45
46 self.fig, (self.ax1, self.ax2) = plt.subplots(2, 1, figsize=(12, 8), gridspec_kw={'height_ratios': [9, 1]})
47 self.fig.tight_layout()
48 self.canvas = FigureCanvas(self.fig)
49
50 self.layout.addWidget(self.canvas)
51
52 self.toolbar = NavigationToolbar(self.canvas, self)
53 self.layout.addWidget(self.toolbar)
54
55 self.x = np.arange(0, 2 * CHUNK, 2)
56 self.line1, = self.ax1.plot(self.x, np.random.rand(CHUNK))
57 self.line2, = self.ax2.plot(self.x, np.random.rand(CHUNK))
58
59 self.legend_elements = [
60 Line2D([0, 4], [0], color='yellow', lw=4, label='DELTA (0hz-4hz)'),
61 Line2D([4, 7], [0], color='blue', lw=4, label='THETA (4hz-7hz)'),
62 Line2D([8, 12], [0], color='green', lw=4, label='ALPHA (8hz-12hz)'),
63 Line2D([12, 30], [0], color='red', lw=4, label='BETA (12hz-30hz)'),
64 Line2D([30, 100], [0], color='purple', lw=4, label='GAMMA (30hz-100hz)')
65 ]
66
67 def update_plot(self):
68 data = np.frombuffer(stream.read(CHUNK), dtype=np.int16)
69 data = np.abs(data)
70 voltage_data = data * (3.3 / 1024) # Voltage to "mV"
71 frequency = voltage_data / (RATE * 1000) # Calculate to frequency
72
73 self.line1.set_ydata(data)
74 self.line2.set_ydata(frequency)
75
76 for coll in self.ax1.collections:
77 coll.remove()
78
79 self.ax1.fill_between(self.x, data, where=((self.x >= 0) & (self.x <= 4)), color='yellow', alpha=1)
80 self.ax1.fill_between(self.x, data, where=((self.x >= 4) & (self.x <= 7)), color='blue', alpha=1)
81 self.ax1.fill_between(self.x, data, where=((self.x >= 8) & (self.x <= 12)), color='green', alpha=1)
82 self.ax1.fill_between(self.x, data, where=((self.x >= 12) & (self.x <= 30)), color='red', alpha=1)
83 self.ax1.fill_between(self.x, data, where=((self.x >= 30) & (self.x <= 100)), color='purple', alpha=1)
84
85 self.ax1.legend(handles=self.legend_elements, loc='upper right')
86 self.ax1.set_ylabel('Amplitude (uV)')
87 self.ax1.set_xlabel('Frequency (Hz)')
88 self.ax1.set_title('Frequency and mV')
89
90 self.ax2.set_ylabel('Voltage (mV)')
91 self.ax2.set_xlabel('Time')
92
93 self.canvas.draw()
94
95 def close_application(self):
96 self.timer.stop()
97 stream.stop_stream()
98 stream.close()
99 p.terminate()
100 sys.exit(app.exec_())
101
102
103if __name__ == '__main__':
104 app = QApplication(sys.argv)
105 mainWin = MainWindow()
106 mainWin.show()
107 sys.exit(app.exec_())1import numpy as np
2import pandas as pd
3from sklearn.preprocessing import StandardScaler
4from tensorflow.keras.models import load_model
5
6model_path = 'model-path'
7new_data_path = 'dataset-path'
8
9model = load_model(model_path)
10
11new_data = pd.read_csv(new_data_path)
12
13X_new = new_data.drop('label', axis=1)
14y_new = new_data['label']
15
16scaler = StandardScaler()
17X_new_scaled = scaler.fit_transform(X_new)
18X_new_reshaped = X_new_scaled.reshape((X_new_scaled.shape[0], 1, X_new_scaled.shape[1]))
19
20predictions = model.predict(X_new_reshaped)
21predicted_labels = np.argmax(predictions, axis=1)
22
23label_mapping = {'NEGATIVE': 0, 'NEUTRAL': 1, 'POSITIVE': 2}
24label_mapping_reverse = {v: k for k, v in label_mapping.items()}
25actual_labels = y_new.replace(label_mapping).values
26
27accuracy = np.mean(predicted_labels == actual_labels)
28
29new_input = np.random.rand(2548, 2548) # 1 sample and 2548 features
30new_input_scaled = scaler.transform(new_input)
31new_input_reshaped = new_input_scaled.reshape((new_input_scaled.shape[0], 1, new_input_scaled.shape[1]))
32
33new_prediction = model.predict(new_input_reshaped)
34predicted_label = np.argmax(new_prediction, axis=1)[0]
35predicted_emotion = label_mapping_reverse[predicted_label]
36
37
38# TR Lang
39if predicted_emotion == 'NEGATIVE':
40 predicted_emotion = 'Negatif'
41elif predicted_emotion == 'NEUTRAL':
42 predicted_emotion = 'Nötr'
43elif predicted_emotion == 'POSITIVE':
44 predicted_emotion = 'Pozitif'
45
46print(f'Inputs: {new_input}')
47print(f'Predicted Emotion: {predicted_emotion}')
48print(f'Accuracy: %{accuracy * 100:.5f}')pip install -r requirements.txt