def test(): network = SimpleConvNet(input_dim=(3,128,128), conv_param = {'filter_num': [32,32], 'filter_size': [3,3], 'pad': [1,1], 'stride': [1,1]}, hidden_size=100, output_size=12, weight_init_std=0.01) network.load_params("params.pkl") data_transform = transforms.Compose([ transforms.RandomResizedCrop(128), transforms.ToTensor(), transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) ]) path = join('dataset\plant-seedlings-classification', 'test') sample_submission = pd.read_csv('sample_submission.csv') submission = sample_submission.copy() for i, f in enumerate(sample_submission['file']): print(join(path, f)) image = Image.open(join(path, f)) #convert image if image.mode != "RGB": image = image.convert("RGB") image = data_transform(image) image = np.expand_dims(image, axis=0) output = network.predict(image) output = np.argmax(output, axis=1) submission['species'][i] = one_hot_key[output[0]] submission.to_csv('submission.csv', index=False)
ny = int(np.ceil(show_num / nx)) fig = plt.figure() fig.subplots_adjust(left=0, right=1, bottom=0, top=1, hspace=0.05, wspace=0.05) for i in range(show_num): ax = fig.add_subplot(4, 4, i+1, xticks=[], yticks=[]) ax.imshow(filters[i, 0], cmap=plt.cm.gray_r, interpolation='nearest') network = SimpleConvNet(input_dim=(1,28,28), conv_param = {'filter_num':30, 'filter_size':5, 'pad':0, 'stride':1}, hidden_size=100, output_size=10, weight_init_std=0.01) # 学習後の重み network.load_params("params.pkl") filter_show(network.params['W1'], 16) img = imread('../dataset/lena_gray.png') img = img.reshape(1, 1, *img.shape) fig = plt.figure() w_idx = 1 for i in range(16): w = network.params['W1'][i] b = 0 # network.params['b1'][i] w = w.reshape(1, *w.shape)
ax.imshow(filters[i, 0], cmap=plt.cm.gray_r, interpolation='nearest') network = SimpleConvNet(input_dim=(1, 28, 28), conv_param={ 'filter_num': 30, 'filter_size': 5, 'pad': 0, 'stride': 1 }, hidden_size=100, output_size=10, weight_init_std=0.01) # 学习后的权重 network.load_params("params.pkl") filter_show(network.params['W1'], 16) img = imread('../dataset/lena_gray.png') img = img.reshape(1, 1, *img.shape) fig = plt.figure() w_idx = 1 for i in range(16): w = network.params['W1'][i] b = 0 # network.params['b1'][i] w = w.reshape(1, *w.shape)
@author: ghqls """ import numpy as np import matplotlib.pyplot as plt from simple_convnet import SimpleConvNet def filter_show(filters, nx=8, margin=3, scale=10): FN, C, FH, FW = filters.shape ny = int(np.ceil(FN / nx)) fig = plt.figure() fig.subplots_adjust(left=0, right=1, bottom=0, top=1, hspace=0.05, wspace=0.05) for i in range(FN): ax = fig.add_subplot(ny, nx, i + 1, xticks=[], yticks=[]) ax.imshow(filters[i, 0], cmap=plt.cm.gray_r, interpolation='nearest') plt.show() network = SimpleConvNet() filter_show(network.params['W1']) network.load_params('params.pkl') filter_show(network.params['W1'])
(_, _), (x_test, _) = load_mnist(normalize=True, flatten=False, one_hot_label=False) # 初始化网络 # 网络1:简单CNN """ conv - relu - pool - affine - relu - affine - softmax """ # 建立一个卷积神经网络的类。 # 本人对于卷积神经网络还不是很了解,不过其实现思路和我前面写的my_app_cnn中的卷积神经网络的步骤相同。 # 关于卷积神经网络将在后面学习,但是这次没有使用tf network = SimpleConvNet(input_dim=(1,28,28), conv_param = {'filter_num': 30, 'filter_size': 5, 'pad': 0, 'stride': 1}, hidden_size=100, output_size=10, weight_init_std=0.01) network.load_params("mnist-master\mnist-master\params.pkl") # 网络2:深度CNN # network = DeepConvNet() # network.load_params("deep_convnet_params.pkl") class MainWindow(QMainWindow,Ui_MainWindow): def __init__(self): # 初始化继承的父类(Qmainwindow) super(MainWindow,self).__init__() # 初始化参数 self.mode = MODE_MNIST self.result = [0, 0]
ax.imshow(filters[i, 0], cmap=plt.cm.gray_r, interpolation='nearest') network = SimpleConvNet(input_dim=(1, 28, 28), conv_param={ 'filter_num': 30, 'filter_size': 5, 'pad': 0, 'stride': 1 }, hidden_size=100, output_size=10, weight_init_std=0.01) # 学習後の重み network.load_params("./ch07/params.pkl") filter_show(network.params['W1'], 16) img = imread('./dataset/lena_gray.png') img = img.reshape(1, 1, *img.shape) fig = plt.figure() w_idx = 1 for i in range(16): w = network.params['W1'][i] b = 0 # network.params['b1'][i] w = w.reshape(1, *w.shape)
def filter_show(filters, nx=8, margin=3, scale=10): """ c.f. https://gist.github.com/aidiary/07d530d5e08011832b12#file-draw_weight-py """ FN, C, FH, FW = filters.shape ny = int(np.ceil(FN / nx)) fig = plt.figure() fig.subplots_adjust(left=0, right=1, bottom=0, top=1, hspace=0.05, wspace=0.05) for i in range(FN): ax = fig.add_subplot(ny, nx, i + 1, xticks=[], yticks=[]) ax.imshow(filters[i, 0], cmap=plt.cm.gray_r, interpolation='nearest') plt.show() network = SimpleConvNet() # ランダム初期化後の重み ##filter_show(network.params['W1']) # 学習後の重み network.load_params("deep_convnet_params9.pkl") filter_show(network.params['W1'])