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
| all_rollings_df_X = all_rollings_df.drop(columns=['RUL']) | |
| extracted_features = extract_features(all_rollings_df_X, | |
| column_id="instance_id", column_sort="time", | |
| n_jobs=4, default_fc_parameters=tsfresh.feature_extraction.settings.MinimalFCParameters()) | |
| impute(extracted_features) | |
| features_filtered = select_features(extracted_features, y_train_rolling, n_jobs=4) | |
| def get_last_window_from_unit(group_df): | |
| res_df = group_df[[x for x in test_df.columns if 'sensor_' in x]].iloc[-10:] |
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 avg_diff(series): | |
| return np.mean(np.diff(series)) | |
| all_rollings_grouped = all_rollings_df_X.drop(columns=['time']).groupby('instance_id').agg(['mean', avg_diff, 'std', 'max', 'min']) | |
| test_df_grouped = test_df.sort_values(['unit_number', 'time']).groupby('unit_number').\ | |
| apply(lambda group_df: group_df[[x for x in test_df.columns if 'sensor_' in x]].\ | |
| iloc[-WINDOW_SIZE:]).reset_index() | |
| test_df_aggregated = test_df_grouped.drop(columns=['level_1']).groupby('unit_number').agg(['mean', avg_diff, 'std', 'max', 'min']) |
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 torch.utils.data import TensorDataset | |
| class RULDataModule(pl.LightningDataModule): | |
| def __init__(self, X_train, y_train, X_val, y_val, X_test, y_test, | |
| batch_size): | |
| super().__init__() | |
| self.X_train = X_train | |
| self.y_train = y_train | |
| self.X_val = X_val | |
| self.y_val = y_val |
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 RULModel(nn.Module): | |
| def __init__(self, n_features, n_hidden=256, n_layers=3): | |
| super().__init__() | |
| self.lstm = nn.LSTM( | |
| input_size=n_features, | |
| hidden_size=n_hidden, | |
| num_layers=n_layers, | |
| batch_first=True, | |
| dropout=0.75 | |
| ) |
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') |
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()) |
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
| 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 |
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
| 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) |