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 | |
| from PyQt6.QtWidgets import QApplication, QHBoxLayout, QMainWindow, QPushButton, QSpinBox, QVBoxLayout, QWidget, QFileDialog, QLabel, QErrorMessage | |
| from PyQt6.QtGui import QImage, QPixmap | |
| import cv2 | |
| import numpy as np | |
| class ImageWidget(QLabel): | |
| def __init__(self, parent=None): | |
| super().__init__(parent) |
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 resize_image(image_data, max_img_width, max_img_height): | |
| scale_percent = min(max_img_width / image_data.shape[1], max_img_height / image_data.shape[0]) | |
| width = int(image_data.shape[1] * scale_percent) | |
| height = int(image_data.shape[0] * scale_percent) | |
| newSize = (width, height) | |
| image_resized = cv2.resize(image_data, newSize, None, None, None, cv2.INTER_AREA) | |
| return image_resized | |
| def pixmap_from_cv_image(cv_image): |
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 choose_source_image(self): | |
| self.source_filename = QFileDialog.getOpenFileName()[0] | |
| self.source_image_data = cv2.imread(self.source_filename) | |
| source_image_resized = resize_image(self.source_image_data, self.max_img_width, self.max_img_height) | |
| self.source_image.setPixmap(pixmap_from_cv_image(source_image_resized)) | |
| def process_image(self): | |
| if self.source_image_data is None: | |
| error_dialog = QErrorMessage() | |
| error_dialog.showMessage('No image selected') |
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
| bottom_bar_layout = QHBoxLayout() | |
| self.save_button = QPushButton('Save as file') | |
| self.save_button.clicked.connect(self.save_as_file) | |
| self.save_button.setFixedWidth(300) | |
| bottom_bar_layout.addWidget(self.save_button) | |
| self.percent_traced_label = QLabel() | |
| bottom_bar_layout.addWidget(self.percent_traced_label) | |
| main_layout.addLayout(top_bar_layout) | |
| main_layout.addLayout(image_bar_layout) |
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
| top_bar_layout.addWidget(select_image_button) | |
| top_bar_layout.addWidget(self.r_select) | |
| top_bar_layout.addWidget(self.g_select) | |
| top_bar_layout.addWidget(self.b_select) | |
| top_bar_layout.addWidget(self.threshold_select) | |
| top_bar_layout.addWidget(process_image_button) | |
| self.source_image = ImageWidget() | |
| self.result_image = ImageWidget() | |
| self.source_image.setMaximumSize(self.max_img_width, self.max_img_height) |
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
| select_image_button = QPushButton('Select Image') | |
| process_image_button = QPushButton('Process!') | |
| select_image_button.clicked.connect(self.choose_source_image) | |
| process_image_button.clicked.connect(self.process_image) | |
| for btn in [select_image_button, process_image_button]: | |
| btn.setFixedHeight(30) | |
| btn.setFixedWidth(100) | |
| self.r_select = QSpinBox() | |
| self.g_select = QSpinBox() | |
| self.b_select = QSpinBox() |
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
| class MainWindow(QMainWindow): | |
| def __init__(self): | |
| super(MainWindow, self).__init__() | |
| self.setWindowTitle("Image Tracer") | |
| main_layout = QVBoxLayout() | |
| top_bar_layout = QHBoxLayout() | |
| image_bar_layout = QHBoxLayout() | |
| self.source_filename = None |
We can make this file beautiful and searchable if this error is corrected: It looks like row 6 should actually have 29 columns, instead of 15 in line 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
| ,unit_number,time,sensor_1,sensor_2,sensor_3,sensor_4,sensor_5,sensor_6,sensor_7,sensor_8,sensor_9,sensor_10,sensor_11,sensor_12,sensor_13,sensor_14,sensor_15,sensor_16,sensor_17,sensor_18,sensor_19,sensor_20,sensor_21,sensor_22,sensor_23,sensor_24,sensor_25,sensor_26 | |
| 0,1,1,-0.0007,-0.0004,100.0,518.67,641.82,1589.7,1400.6,14.62,21.61,554.36,2388.06,9046.19,1.3,47.47,521.66,2388.02,8138.62,8.4195,0.03,392,2388,100.0,39.06,23.419,, | |
| 1,1,2,0.0019,-0.0003,100.0,518.67,642.15,1591.82,1403.14,14.62,21.61,553.75,2388.04,9044.07,1.3,47.49,522.28,2388.07,8131.49,8.4318,0.03,392,2388,100.0,39.0,23.4236,, | |
| 2,1,3,-0.0043,0.0003,100.0,518.67,642.35,1587.99,1404.2,14.62,21.61,554.26,2388.08,9052.94,1.3,47.27,522.42,2388.03,8133.23,8.4178,0.03,390,2388,100.0,38.95,23.3442,, | |
| 3,1,4,0.0007,0.0,100.0,518.67,642.35,1582.79,1401.87,14.62,21.61,554.45,2388.11,9049.48,1.3,47.13,522.86,2388.08,8133.83,8.3682,0.03,392,2388,100.0,38.88,23.3739,, | |
| 4,1,5,-0.0019,-0.0002,100.0,518.67,642.37,1582.85,1406.22,14.62,21.61,554.0,2388.06,9055.15 |
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 tqdm import tqdm | |
| def get_predictions_and_labels_lstm(dataset): | |
| predictions = [] | |
| labels = [] | |
| for item in tqdm(test_dataset): | |
| X, y = item | |
| _, output = trained_model(X.unsqueeze(dim=0)) | |
| predictions.append(output.item()) | |
| labels.append(y.item()) |
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
| checkpoint_callback = ModelCheckpoint( | |
| dirpath='checkpoints', | |
| filename='best-checkpoint', | |
| save_top_k=1, | |
| verbose=True, | |
| monitor='val_loss', | |
| mode='min' | |
| ) | |
| logger = TensorBoardLogger('lightning_logs', name='RUL') |