-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
434 additions
and
263 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains 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
Binary file not shown.
This file contains 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
This file contains 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
Binary file not shown.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
2018-02-16 22:45:03 TENSOR_Adam_Dropout0.7_RELU epoch: 0 , batch: 50 , avg_batch_acc: 0.2188 avg_batch_loss: 3.4016 learning_rate 0.000500 | ||
2018-02-16 22:47:25 TENSOR_Adam_Dropout0.7_RELU epoch: 0 , batch: 100 , avg_batch_acc: 0.2500 avg_batch_loss: 2.6438 learning_rate 0.000500 | ||
2018-02-16 22:50:03 TENSOR_Adam_Dropout0.7_RELU epoch: 0 , batch: 150 , avg_batch_acc: 0.2344 avg_batch_loss: 1.9562 learning_rate 0.000500 | ||
2018-02-16 22:52:44 TENSOR_Adam_Dropout0.7_RELU epoch: 0 , batch: 200 , avg_batch_acc: 0.5625 avg_batch_loss: 1.3707 learning_rate 0.000500 | ||
2018-02-16 22:55:24 TENSOR_Adam_Dropout0.7_RELU epoch: 0 , batch: 250 , avg_batch_acc: 0.5312 avg_batch_loss: 1.3155 learning_rate 0.000500 | ||
2018-02-16 22:58:02 TENSOR_Adam_Dropout0.7_RELU epoch: 0 , batch: 300 , avg_batch_acc: 0.6250 avg_batch_loss: 1.0030 learning_rate 0.000500 | ||
2018-02-16 23:00:41 TENSOR_Adam_Dropout0.7_RELU epoch: 0 , batch: 350 , avg_batch_acc: 0.6875 avg_batch_loss: 1.1672 learning_rate 0.000500 | ||
2018-02-16 23:03:20 TENSOR_Adam_Dropout0.7_RELU epoch: 0 , batch: 400 , avg_batch_acc: 0.6719 avg_batch_loss: 0.8919 learning_rate 0.000500 | ||
2018-02-16 23:05:59 TENSOR_Adam_Dropout0.7_RELU epoch: 0 , batch: 450 , avg_batch_acc: 0.6875 avg_batch_loss: 0.6986 learning_rate 0.000500 | ||
2018-02-16 23:08:37 TENSOR_Adam_Dropout0.7_RELU epoch: 0 , batch: 500 , avg_batch_acc: 0.7969 avg_batch_loss: 0.5889 learning_rate 0.000500 | ||
2018-02-16 23:11:18 TENSOR_Adam_Dropout0.7_RELU epoch: 0 , batch: 550 , avg_batch_acc: 0.7812 avg_batch_loss: 0.6626 learning_rate 0.000500 | ||
2018-02-16 23:13:58 TENSOR_Adam_Dropout0.7_RELU epoch: 0 , batch: 600 , avg_batch_acc: 0.7500 avg_batch_loss: 0.5585 learning_rate 0.000500 | ||
2018-02-16 23:16:42 TENSOR_Adam_Dropout0.7_RELU epoch: 0 , batch: 650 , avg_batch_acc: 0.8125 avg_batch_loss: 0.6408 learning_rate 0.000500 | ||
2018-02-16 23:19:23 TENSOR_Adam_Dropout0.7_RELU epoch: 0 , batch: 700 , avg_batch_acc: 0.7969 avg_batch_loss: 0.6765 learning_rate 0.000500 | ||
2018-02-16 23:22:03 TENSOR_Adam_Dropout0.7_RELU epoch: 0 , batch: 750 , avg_batch_acc: 0.7969 avg_batch_loss: 0.5936 learning_rate 0.000500 | ||
2018-02-16 23:24:39 TENSOR_Adam_Dropout0.7_RELU epoch: 0 , batch: 800 , avg_batch_acc: 0.8750 avg_batch_loss: 0.3763 learning_rate 0.000500 | ||
2018-02-16 23:27:18 TENSOR_Adam_Dropout0.7_RELU epoch: 0 , batch: 850 , avg_batch_acc: 0.9062 avg_batch_loss: 0.4242 learning_rate 0.000500 | ||
2018-02-16 23:29:56 TENSOR_Adam_Dropout0.7_RELU epoch: 0 , batch: 900 , avg_batch_acc: 0.8125 avg_batch_loss: 0.5433 learning_rate 0.000500 |
Empty file.
Binary file not shown.
This file contains 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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,96 @@ | ||
import tensor.Variable as var | ||
import tensor.Operator as op | ||
|
||
from layers.base_conv import Conv2D | ||
from layers.pooling import MaxPooling | ||
from layers.fc import FullyConnect | ||
from layers.relu import Relu | ||
from layers.softmax import Softmax | ||
# from layers.base_conv import Conv2D | ||
# from layers.pooling import MaxPooling | ||
# from layers.fc import FullyConnect | ||
# from layers.relu import Relu | ||
# from layers.softmax import Softmax | ||
|
||
import cv2 | ||
# import cv2 | ||
import numpy as np | ||
|
||
img = cv2.imread('layers/test.jpg') | ||
img = img[np.newaxis, :] | ||
# img = cv2.imread('layers/test.jpg') | ||
# img = img[np.newaxis, :] | ||
|
||
e=1e-3 | ||
a = var.Variable((1, 128, 128, 3), 'a') | ||
label = var.Variable([1, 1], 'label') | ||
import random | ||
label.data = np.array([random.randint(1,9)]) | ||
label.data = label.data.astype(int) | ||
b = var.Variable((1, 128, 128, 3), 'b') | ||
|
||
b.data = a.data.copy() | ||
a.data[0,0,0,1] += e | ||
b.data[0,0,0,1] -= e | ||
|
||
# label = var.Variable([1, 1], 'label') | ||
# import random | ||
# label.data = np.array([random.randint(1,9)]) | ||
# label.data = label.data.astype(int) | ||
|
||
import numpy as np | ||
conv1_out = op.Conv2D((3, 3, 3, 3), input_variable=a, name='conv1',padding='VALID').output_variables | ||
relu1_out = op.Relu(input_variable=conv1_out, name='relu1').output_variables | ||
pool1_out = op.MaxPooling(ksize=2, input_variable=relu1_out, name='pool1').output_variables | ||
fc1_out = op.FullyConnect(output_num=10, input_variable=pool1_out, name='fc1').output_variables | ||
sf_out = op.SoftmaxLoss(predict=fc1_out,label=label,name='sf').loss | ||
conv2_out = op.Conv2D((3, 3, 3, 3), input_variable=b, name='conv2',padding='VALID').output_variables | ||
|
||
new_conv1 = op.GLOBAL_VARIABLE_SCOPE['conv1'] | ||
new_fc1 = op.GLOBAL_VARIABLE_SCOPE['fc1'] | ||
conv1 = var.GLOBAL_VARIABLE_SCOPE['conv1'] | ||
conv2 = var.GLOBAL_VARIABLE_SCOPE['conv2'] | ||
var.GLOBAL_VARIABLE_SCOPE['conv1'].weights.data = var.GLOBAL_VARIABLE_SCOPE['conv2'].weights.data | ||
var.GLOBAL_VARIABLE_SCOPE['conv1'].bias.data = var.GLOBAL_VARIABLE_SCOPE['conv2'].bias.data | ||
|
||
# print conv1.weights.data - conv2.weights.data | ||
# print conv1_out.eval()-conv2_out.eval() | ||
|
||
conv1 = Conv2D([1, 128, 128, 3], 3, 3, 1,method='VALID') | ||
relu1 = Relu(conv1.output_shape) | ||
pool1 = MaxPooling(conv1.output_shape) | ||
fc1 = FullyConnect(pool1.output_shape,10) | ||
sf = Softmax(fc1.output_shape) | ||
|
||
conv1.weights = new_conv1.weights.data | ||
conv1.bias = new_conv1.bias.data | ||
fc1.weights = new_fc1.weights.data | ||
fc1.bias = new_fc1.bias.data | ||
conv1_out.eval() | ||
conv1_out.diff.data = (np.ones(conv1_out.diff.shape)) | ||
print a.wait_bp, conv1.wait_forward | ||
|
||
conv2_out.eval() | ||
conv2_out.diff.data = (np.ones(conv1_out.diff.shape)) | ||
print b.wait_bp, conv2.wait_forward | ||
|
||
out = sf.cal_loss(fc1.forward(pool1.forward(relu1.forward(conv1.forward(img)))), label.data) | ||
sf.gradient() | ||
eta = conv1.gradient(relu1.gradient(pool1.gradient(fc1.gradient(sf.eta)))) | ||
# print a.diff_eval()[0,0,0,1] | ||
|
||
|
||
|
||
# relu1_out = op.Relu(input_variable=conv1_out, name='relu1').output_variables | ||
# pool1_out = op.MaxPooling(ksize=2, input_variable=relu1_out, name='pool1').output_variables | ||
# fc1_out = op.FullyConnect(output_num=10, input_variable=pool1_out, name='fc1').output_variables | ||
# sf_out = op.SoftmaxLoss(predict=fc1_out,label=label,name='sf').loss | ||
# | ||
# new train op | ||
# give value and forward | ||
a.data = img | ||
new_out = sf_out.eval() | ||
# new_conv1 = op.GLOBAL_VARIABLE_SCOPE['conv1'] | ||
# new_fc1 = op.GLOBAL_VARIABLE_SCOPE['fc1'] | ||
|
||
# give diff and backward | ||
new_eta = a.diff_eval() | ||
print new_eta-eta | ||
|
||
|
||
for k in var.GLOBAL_VARIABLE_SCOPE: | ||
s = var.GLOBAL_VARIABLE_SCOPE[k] | ||
if isinstance(s,var.Variable) and s.learnable: | ||
print s.name, s.parent, s.child | ||
# conv1 = Conv2D([1, 128, 128, 3], 3, 3, 1,method='VALID') | ||
# relu1 = Relu(conv1.output_shape) | ||
# pool1 = MaxPooling(conv1.output_shape) | ||
# fc1 = FullyConnect(pool1.output_shape,10) | ||
# sf = Softmax(fc1.output_shape) | ||
# | ||
# conv1.weights = new_conv1.weights.data | ||
# conv1.bias = new_conv1.bias.data | ||
# fc1.weights = new_fc1.weights.data | ||
# fc1.bias = new_fc1.bias.data | ||
# | ||
# | ||
# out = sf.cal_loss(fc1.forward(pool1.forward(relu1.forward(conv1.forward(img)))), label.data) | ||
# sf.gradient() | ||
# eta = conv1.gradient(relu1.gradient(pool1.gradient(fc1.gradient(sf.eta)))) | ||
|
||
|
||
# | ||
# new train op | ||
# give value and forward | ||
# a.data = img | ||
# new_out = sf_out.eval() | ||
# | ||
# # give diff and backward | ||
# new_eta = a.diff_eval() | ||
# print new_eta-eta | ||
# | ||
# | ||
# for k in var.GLOBAL_VARIABLE_SCOPE: | ||
# s = var.GLOBAL_VARIABLE_SCOPE[k] | ||
# if isinstance(s,var.Variable) and s.learnable: | ||
# print s.name, s.parent, s.child |