Skip to content

Commit 31e6123

Browse files
committed
Update Algorithms
1 parent b9ace63 commit 31e6123

File tree

18 files changed

+1554
-1579
lines changed

18 files changed

+1554
-1579
lines changed

NN/Basic/Networks.py

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def __init__(self):
4545

4646
self._whether_apply_bias = False
4747
self._current_dimension = 0
48-
self._cost_layer = "Undefined"
4948

5049
self._logs = {}
5150
self._timings = {}
@@ -92,7 +91,6 @@ def initialize(self):
9291

9392
self._whether_apply_bias = False
9493
self._current_dimension = 0
95-
self._cost_layer = "Undefined"
9694

9795
self._logs = []
9896
self._timings = {}
@@ -245,19 +243,6 @@ def _add_layer(self, layer, *args, **kwargs):
245243
self._current_dimension = _next
246244
self._update_layer_information(layer)
247245

248-
@NNTiming.timeit(level=4)
249-
def _add_cost_layer(self, output_dim):
250-
last_layer = self._layers[-1]
251-
last_layer_root = last_layer.root
252-
if not isinstance(last_layer, CostLayer):
253-
if last_layer_root.name == "Sigmoid" or last_layer_root.name == "Softmax":
254-
self._cost_layer = "CrossEntropy"
255-
else:
256-
self._cost_layer = "MSE"
257-
self.add(self._cost_layer, (output_dim,))
258-
else:
259-
self._cost_layer = last_layer.cost_function
260-
261246
@NNTiming.timeit(level=4)
262247
def _update_layer_information(self, layer):
263248
self._layer_params.append(layer.params)
@@ -278,7 +263,7 @@ def _get_prediction(self, x, name=None, batch_size=1e6, verbose=None):
278263
if not len(x) % single_batch:
279264
epoch += 1
280265
name = "Prediction" if name is None else "Prediction ({})".format(name)
281-
sub_bar = ProgressBar(max_value=epoch, name=name)
266+
sub_bar = ProgressBar(max_value=epoch, name=name, start=False)
282267
if verbose >= NNVerbose.METRICS:
283268
sub_bar.start()
284269
rs, count = [self._get_activations(x[:single_batch], predict=True).pop()], single_batch
@@ -413,7 +398,7 @@ def _draw_detailed_network(self, show, radius=6, width=1200, height=800, padding
413398
graph_group.append(data)
414399
graphs.append(graph_group)
415400

416-
img = np.ones((height, width, 3), np.uint8) * 255
401+
img = np.full([height, width, 3], 255, dtype=np.uint8)
417402
axis0_padding = int(height / (layers - 1 + 2 * padding)) * padding + plot_num
418403
axis0_step = (height - 2 * axis0_padding) / layers
419404
sub_layer_decrease = int((1 - sub_layer_height_scale) * axis0_step)
@@ -676,7 +661,7 @@ def preview(self):
676661
) if isinstance(_layer, ConvLayer) else "Layer : {:<10s} - {}".format(
677662
_layer.name, _layer.shape[1]
678663
) for _layer in self._layers[:-1]
679-
]) + "\nCost : {:<10s}".format(self._cost_layer)
664+
]) + "\nCost : {:<10s}".format(str(self._layers[-1]))
680665
)
681666
print("=" * 30 + "\n" + "Structure\n" + "-" * 30 + "\n" + rs + "\n" + "-" * 30 + "\n")
682667

@@ -786,13 +771,13 @@ def fit(self,
786771
layer_width = len(self._layers)
787772
self._whether_apply_bias = apply_bias
788773

789-
bar = ProgressBar(max_value=max(1, epoch // record_period), name="Epoch")
774+
bar = ProgressBar(max_value=max(1, epoch // record_period), name="Epoch", start=False)
790775
if self.verbose >= NNVerbose.EPOCH:
791776
bar.start()
792777
img, ims = None, []
793778

794779
weight_trace = [[[org] for org in weight] for weight in self._weights]
795-
sub_bar = ProgressBar(max_value=train_repeat * record_period - 1, name="Iteration")
780+
sub_bar = ProgressBar(max_value=train_repeat * record_period - 1, name="Iteration", start=False)
796781
for counter in range(epoch):
797782
self._w_optimizer.update()
798783
self._b_optimizer.update()
@@ -875,7 +860,7 @@ def fit(self,
875860
if self.verbose >= NNVerbose.EPOCH:
876861
bar.update(counter // record_period + 1)
877862
if self.verbose >= NNVerbose.ITER:
878-
sub_bar = ProgressBar(max_value=train_repeat * record_period - 1, name="Iteration")
863+
sub_bar = ProgressBar(max_value=train_repeat * record_period - 1, name="Iteration", start=False)
879864

880865
if do_log:
881866
self._append_log(x_test, y_test, "test", get_loss=show_loss)

NN/TF/Networks.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ def _get_prediction(self, x, name=None, verbose=None, out_of_sess=False):
471471
if not len(x) % single_batch:
472472
epoch += 1
473473
name = "Prediction" if name is None else "Prediction ({})".format(name)
474-
sub_bar = ProgressBar(max_value=epoch, name=name)
474+
sub_bar = ProgressBar(max_value=epoch, name=name, start=False)
475475
if verbose >= NNVerbose.METRICS:
476476
sub_bar.start()
477477
rs, count = [], 0
@@ -583,7 +583,7 @@ def _draw_detailed_network(self, radius=6, width=1200, height=800, padding=0.2,
583583
_graph_group.append(data)
584584
_graphs.append(_graph_group)
585585

586-
img = np.ones((height, width, 3), np.uint8) * 255
586+
img = np.full([height, width, 3], 255, dtype=np.uint8)
587587
axis0_padding = int(height / (layers - 1 + 2 * padding)) * padding + plot_num
588588
axis0_step = (height - 2 * axis0_padding) / layers
589589
sub_layer_decrease = int((1 - sub_layer_height_scale) * axis0_step)
@@ -819,7 +819,7 @@ def fit(self,
819819
if verbose is not None:
820820
self.verbose = verbose
821821

822-
bar = ProgressBar(max_value=max(1, epoch // record_period), name="Epoch")
822+
bar = ProgressBar(max_value=max(1, epoch // record_period), name="Epoch", start=False)
823823
if self.verbose >= NNVerbose.EPOCH:
824824
bar.start()
825825
img = None
@@ -863,7 +863,7 @@ def fit(self,
863863
train_writer = test_writer = train_merge_op = test_merge_op = None
864864

865865
y_train_pred = y_test_pred = None
866-
sub_bar = ProgressBar(max_value=train_repeat * record_period - 1, name="Iteration")
866+
sub_bar = ProgressBar(max_value=train_repeat * record_period - 1, name="Iteration", start=False)
867867
for counter in range(epoch):
868868
if self.verbose >= NNVerbose.ITER and counter % record_period == 0:
869869
sub_bar.start()
@@ -911,7 +911,8 @@ def fit(self,
911911
if self.verbose >= NNVerbose.EPOCH:
912912
bar.update(counter // record_period + 1)
913913
if self.verbose >= NNVerbose.ITER:
914-
sub_bar = ProgressBar(max_value=train_repeat * record_period - 1, name="Iteration")
914+
sub_bar = ProgressBar(
915+
max_value=train_repeat * record_period - 1, name="Iteration", start=False)
915916

916917
if img is not None:
917918
cv2.waitKey(0)
@@ -1176,7 +1177,6 @@ def predict(self, x):
11761177
epoch = int(ceil(len(x) / batch_size))
11771178
output = self._sess.graph.get_tensor_by_name(self._output)
11781179
bar = ProgressBar(max_value=epoch, name="Predict")
1179-
bar.start()
11801180
for i in range(epoch):
11811181
if i == epoch - 1:
11821182
rs.append(self._sess.run(output, {

0 commit comments

Comments
 (0)