(
self, patterns, datas_train, datas_teach, n_repeat, error_accuracy, draw_e=bool
)
| 210 | return pd_all |
| 211 | |
| 212 | def train( |
| 213 | self, patterns, datas_train, datas_teach, n_repeat, error_accuracy, draw_e=bool |
| 214 | ): |
| 215 | # model training |
| 216 | print("----------------------Start Training-------------------------") |
| 217 | print((" - - Shape: Train_Data ", np.shape(datas_train))) |
| 218 | print((" - - Shape: Teach_Data ", np.shape(datas_teach))) |
| 219 | rp = 0 |
| 220 | all_mse = [] |
| 221 | mse = 10000 |
| 222 | while rp < n_repeat and mse >= error_accuracy: |
| 223 | error_count = 0 |
| 224 | print(f"-------------Learning Time {rp}--------------") |
| 225 | for p in range(len(datas_train)): |
| 226 | # print('------------Learning Image: %d--------------'%p) |
| 227 | data_train = np.asmatrix(datas_train[p]) |
| 228 | data_teach = np.asarray(datas_teach[p]) |
| 229 | data_focus1, data_conved1 = self.convolute( |
| 230 | data_train, |
| 231 | self.conv1, |
| 232 | self.w_conv1, |
| 233 | self.thre_conv1, |
| 234 | conv_step=self.step_conv1, |
| 235 | ) |
| 236 | data_pooled1 = self.pooling(data_conved1, self.size_pooling1) |
| 237 | shape_featuremap1 = np.shape(data_conved1) |
| 238 | """ |
| 239 | print(' -----original shape ', np.shape(data_train)) |
| 240 | print(' ---- after convolution ',np.shape(data_conv1)) |
| 241 | print(' -----after pooling ',np.shape(data_pooled1)) |
| 242 | """ |
| 243 | data_bp_input = self._expand(data_pooled1) |
| 244 | bp_out1 = data_bp_input |
| 245 | |
| 246 | bp_net_j = np.dot(bp_out1, self.vji.T) - self.thre_bp2 |
| 247 | bp_out2 = self.sig(bp_net_j) |
| 248 | bp_net_k = np.dot(bp_out2, self.wkj.T) - self.thre_bp3 |
| 249 | bp_out3 = self.sig(bp_net_k) |
| 250 | |
| 251 | # --------------Model Leaning ------------------------ |
| 252 | # calculate error and gradient--------------- |
| 253 | pd_k_all = np.multiply( |
| 254 | (data_teach - bp_out3), np.multiply(bp_out3, (1 - bp_out3)) |
| 255 | ) |
| 256 | pd_j_all = np.multiply( |
| 257 | np.dot(pd_k_all, self.wkj), np.multiply(bp_out2, (1 - bp_out2)) |
| 258 | ) |
| 259 | pd_i_all = np.dot(pd_j_all, self.vji) |
| 260 | |
| 261 | pd_conv1_pooled = pd_i_all / (self.size_pooling1 * self.size_pooling1) |
| 262 | pd_conv1_pooled = pd_conv1_pooled.T.getA().tolist() |
| 263 | pd_conv1_all = self._calculate_gradient_from_pool( |
| 264 | data_conved1, |
| 265 | pd_conv1_pooled, |
| 266 | shape_featuremap1[0], |
| 267 | shape_featuremap1[1], |
| 268 | self.size_pooling1, |
| 269 | ) |
nothing calls this directly
no test coverage detected