1. 800x600の白線画像を1/13.333...(0.075)の60x45に縮める。
2. 60x45のうちの下から60x14を中間BMPファイルとしてセーブ
3. 60x14のうちの56x10を切り出してBMPファイルに。1つにつき5x5の25個できる。
4. 左右直進をやる。
Starting C simulation ...
/opt/Xilinx/Vivado_HLS/2016.4/bin/vivado_hls /home/masaaki/Vivado_HLS/ZYBO/straight_conv_nn2/solution1/csim.tcl
INFO: [HLS 200-10] Running '/opt/Xilinx/Vivado_HLS/2016.4/bin/unwrapped/lnx64.o/vivado_hls'
INFO: [HLS 200-10] For user 'masaaki' on host 'masaaki-VirtualBox2' (Linux_x86_64 version 4.4.0-92-generic) on Tue Aug 29 04:13:06 JST 2017
INFO: [HLS 200-10] On os Ubuntu 16.04.3 LTS
INFO: [HLS 200-10] In directory '/home/masaaki/Vivado_HLS/ZYBO'
INFO: [HLS 200-10] Opening project '/home/masaaki/Vivado_HLS/ZYBO/straight_conv_nn2'.
INFO: [HLS 200-10] Opening solution '/home/masaaki/Vivado_HLS/ZYBO/straight_conv_nn2/solution1'.
INFO: [SYN 201-201] Setting up clock 'default' with a period of 10ns.
INFO: [HLS 200-10] Setting target device to 'xc7z010clg400-1'
INFO: [SIM 211-2] *************** CSIM start ***************
INFO: [SIM 211-4] CSIM will launch GCC as the compiler.
Compiling ../../../straight_conv_nn_tb.cpp in debug mode
Generating csim.exe
id = 25, max_id_ref = 1, max_id_hw = 2
id = 25, max_id_ref = 1, max_id_sw = 2
id = 26, max_id_ref = 1, max_id_sw = 2
id = 30, max_id_ref = 1, max_id_sw = 2
id = 35, max_id_ref = 1, max_id_sw = 2
INFO: [SIM 211-1] CSim done with 0 errors.
INFO: [SIM 211-3] *************** CSIM finish ***************
Finished C simulation.
// straight_conv_nn2.cpp
// 2017/08/28 by marsee
// 畳み込み層のカーネル数 2
//
#include <ap_fixed.h>
#include "conv1_weight.h"
#include "conv1_bias.h"
#include "af1_weight.h"
#include "af1_bias.h"
#include "af2_weight.h"
#include "af2_bias.h"
#define NUM_OF_KERNELS 2
#define COULMN_PIXELS 56
#define ROW_PIXELS 10
#define ALL_PIXELS 560
#define NUM_OF_OUTPUT 3
int straight_conv_nn(ap_ufixed<8, 0, AP_TRN_ZERO, AP_SAT> in[ALL_PIXELS], ap_fixed<12, 7, AP_TRN_ZERO, AP_SAT> out[NUM_OF_OUTPUT]){
ap_ufixed<8, 0, AP_TRN_ZERO, AP_SAT> buf[ROW_PIXELS][COULMN_PIXELS];
ap_fixed<10, 6, AP_TRN_ZERO, AP_SAT> conv_out[NUM_OF_KERNELS][ROW_PIXELS-4][COULMN_PIXELS-4];
ap_fixed<10, 6, AP_TRN_ZERO, AP_SAT> pool_out[NUM_OF_KERNELS][(ROW_PIXELS-4)/2][(COULMN_PIXELS-4)/2];
ap_fixed<13, 7, AP_TRN_ZERO, AP_SAT> dot1[100];
ap_fixed<13, 7, AP_TRN_ZERO, AP_SAT> dot2[NUM_OF_OUTPUT];
buf_copy1: for(int i=0; i<ROW_PIXELS; i++)
buf_copy2: for(int j=0; j<COULMN_PIXELS; j++)
buf[i][j] = in[i*COULMN_PIXELS+j];
// Convolutional Neural Network 5x5 kernel, Stride = 1, Padding = 0
// + ReLU
CONV1: for(int i=0; i<NUM_OF_KERNELS; i++){ // カーネルの個数
CONV2: for(int j=0; j<ROW_PIXELS-4; j++){
CONV3: for(int k=0; k<COULMN_PIXELS-4; k++){
conv_out[i][j][k] = 0;
CONV4: for(int m=0; m<5; m++){
CONV5: for(int n=0; n<5; n++){
conv_out[i][j][k] += buf[j+m][k+n] * conv1_weight[i][0][m][n];
}
}
conv_out[i][j][k] += conv1_bias[i];
if(conv_out[i][j][k]<0) // ReLU
conv_out[i][j][k] = 0;
}
}
}
// Pooling Kernel = 2 x 2, Stride = 2
POOL1: for(int i=0; i<NUM_OF_KERNELS; i++){
POOL2: for(int j=0; j<ROW_PIXELS-4; j += 2){
POOL3: for(int k=0; k<COULMN_PIXELS-4; k += 2){
POOL4: for(int m=0; m<2; m++){
POOL5: for(int n=0; n<2; n++){
if(m==0 && n==0){
pool_out[i][j/2][k/2] = conv_out[i][j][k];
} else if(pool_out[i][j/2][k/2] < conv_out[i][j+m][k+n]){
pool_out[i][j/2][k/2] = conv_out[i][j+m][k+n];
}
}
}
}
}
}
af1_dot1: for(int col=0; col<100; col++){
dot1[col] = 0;
af1_dot2: for(int i=0; i<NUM_OF_KERNELS; i++){
af1_dot3: for(int j=0; j<(ROW_PIXELS-4)/2; j++){
af1_dot4: for(int k=0; k<(COULMN_PIXELS-4)/2; k++){
dot1[col] += pool_out[i][j][k]*af1_weight[i*((ROW_PIXELS-4)/2)*((COULMN_PIXELS-4)/2)+j*((COULMN_PIXELS-4)/2)+k][col];
}
}
}
dot1[col] += af1_bias[col];
if(dot1[col] < 0) // ReLU
dot1[col] = 0;
}
af2_dot1: for(int col=0; col<NUM_OF_OUTPUT; col++){
dot2[col] = 0;
af2_dot2: for(int row=0; row<100; row++){
dot2[col] += dot1[row]*af2_weight[row][col];
}
dot2[col] += af2_bias[col];
out[col] = dot2[col];
}
return(0);
}
// straight_conv_nn_tb.cpp
// 2017/08/28 by marsee
// 畳み込み層のカーネル数 2
//
#include <stdio.h>
#include <ap_fixed.h>
#include "conv1_weight.h"
#include "conv1_bias.h"
#include "af1_weight.h"
#include "af1_bias.h"
#include "af2_weight.h"
#include "af2_bias.h"
#include "straight_data.h"
#define NUM_OF_KERNELS 2
#define COULMN_PIXELS 56
#define ROW_PIXELS 10
#define ALL_PIXELS 560
#define NUM_OF_OUTPUT 3
int straight_conv_nn(ap_ufixed<8, 0, AP_TRN_ZERO, AP_SAT> in[ALL_PIXELS], ap_fixed<12, 7, AP_TRN_ZERO, AP_SAT> out[NUM_OF_OUTPUT]);
int straight_conv_nn_float(float in[ALL_PIXELS], float out[NUM_OF_OUTPUT]);
int max_ap_fixed(ap_fixed<12, 7, AP_TRN_ZERO, AP_SAT> out[NUM_OF_OUTPUT]);
int max_float(float out[NUM_OF_OUTPUT]);
#define NUM_ITERATIONS 90 // C Simulation
//#define NUM_ITERATIONS 2 // C/RTL CoSimulation
int main(){
float t_tran_float[NUM_ITERATIONS][ALL_PIXELS];
ap_fixed<12, 7, AP_TRN_ZERO, AP_SAT> result_ap_fixed[NUM_ITERATIONS][NUM_OF_OUTPUT];
float result_float[NUM_ITERATIONS][NUM_OF_OUTPUT];
int max_id_hw, max_id_sw, max_id_ref;
for(int i=0; i<NUM_ITERATIONS; i++)
for(int j=0; j<ALL_PIXELS; j++)
t_tran_float[i][j] = (float)t_train[i][j];
for(int i=0; i<NUM_ITERATIONS; i++){
straight_conv_nn(&t_train[i][0], &result_ap_fixed[i][0]);
straight_conv_nn_float(&t_tran_float[i][0], &result_float[i][0]);
}
int errflag=0;
for(int i=0; i<NUM_ITERATIONS; i++){
max_id_hw = max_ap_fixed(&result_ap_fixed[i][0]);
max_id_sw = max_float(&result_float[i][0]);
max_id_ref = max_float(&t_test[i][0]);
if(max_id_ref != max_id_hw){
printf("id = %d, max_id_ref = %d, max_id_hw = %d\n", i, max_id_ref, max_id_hw);
errflag = 1;
}
if(max_id_ref != max_id_sw){
printf("id = %d, max_id_ref = %d, max_id_sw = %d\n", i, max_id_ref, max_id_sw);
errflag = 1;
}
}
if(errflag == 0)
printf("No Error\n");
return(0);
}
int straight_conv_nn_float(float in[ALL_PIXELS], float out[NUM_OF_OUTPUT]){
float buf[ROW_PIXELS][COULMN_PIXELS];
float conv_out[NUM_OF_KERNELS][ROW_PIXELS-4][COULMN_PIXELS-4];
float pool_out[NUM_OF_KERNELS][(ROW_PIXELS-4)/2][(COULMN_PIXELS-4)/2];
float dot1[100];
float dot2[NUM_OF_OUTPUT];
buf_copy1: for(int i=0; i<ROW_PIXELS; i++)
buf_copy2: for(int j=0; j<COULMN_PIXELS; j++)
buf[i][j] = in[i*COULMN_PIXELS+j];
// Convolutional Neural Network 5x5 kernel, Stride = 1, Padding = 0
// + ReLU
CONV1: for(int i=0; i<NUM_OF_KERNELS; i++){ // カーネルの個数
CONV2: for(int j=0; j<ROW_PIXELS-4; j++){
CONV3: for(int k=0; k<COULMN_PIXELS-4; k++){
conv_out[i][j][k] = 0;
CONV4: for(int m=0; m<5; m++){
CONV5: for(int n=0; n<5; n++){
conv_out[i][j][k] += buf[j+m][k+n] * conv1_fweight[i][0][m][n];
}
}
conv_out[i][j][k] += conv1_fbias[i];
if(conv_out[i][j][k]<0) // ReLU
conv_out[i][j][k] = 0;
}
}
}
// Pooling Kernel = 2 x 2, Stride = 2
POOL1: for(int i=0; i<NUM_OF_KERNELS; i++){
POOL2: for(int j=0; j<ROW_PIXELS-4; j += 2){
POOL3: for(int k=0; k<COULMN_PIXELS-4; k += 2){
POOL4: for(int m=0; m<2; m++){
POOL5: for(int n=0; n<2; n++){
if(m==0 && n==0){
pool_out[i][j/2][k/2] = conv_out[i][j][k];
} else if(pool_out[i][j/2][k/2] < conv_out[i][j+m][k+n]){
pool_out[i][j/2][k/2] = conv_out[i][j+m][k+n];
}
}
}
}
}
}
af1_dot1: for(int col=0; col<100; col++){
dot1[col] = 0;
af1_dot2: for(int i=0; i<NUM_OF_KERNELS; i++){
af1_dot3: for(int j=0; j<(ROW_PIXELS-4)/2; j++){
af1_dot4: for(int k=0; k<(COULMN_PIXELS-4)/2; k++){
dot1[col] += pool_out[i][j][k]*af1_fweight[i*((ROW_PIXELS-4)/2)*((COULMN_PIXELS-4)/2)+j*((COULMN_PIXELS-4)/2)+k][col];
}
}
}
dot1[col] += af1_fbias[col];
if(dot1[col] < 0) // ReLU
dot1[col] = 0;
}
af2_dot1: for(int col=0; col<NUM_OF_OUTPUT; col++){
dot2[col] = 0;
af2_dot2: for(int row=0; row<100; row++){
dot2[col] += dot1[row]*af2_fweight[row][col];
}
dot2[col] += af2_fbias[col];
out[col] = dot2[col];
}
return(0);
}
int max_ap_fixed(ap_fixed<12, 7, AP_TRN_ZERO, AP_SAT> out[NUM_OF_OUTPUT]){
int max_id;
ap_fixed<12, 7, AP_TRN_ZERO, AP_SAT> max;
for(int i=0; i<NUM_OF_OUTPUT; i++){
if(i == 0){
max = out[0];
max_id = 0;
}else if(out[i]>max){
max = out[i];
max_id = i;
}
}
return(max_id);
}
int max_float(float out[NUM_OF_OUTPUT]){
int max_id;
float max;
for(int i=0; i<NUM_OF_OUTPUT; i++){
if(i == 0){
max = out[0];
max_id = 0;
}else if(out[i]>max){
max = out[i];
max_id = i;
}
}
return(max_id);
}
def view_straight(first_offset, last_offset):
# 白線追従走行用データセットのfirst_offset(画像の配列の番号)からlast_offset-1までの画像を表示する
# 「ゼロから作るDeep_Learning」第8章のコードを一部引用しています
# coding: utf-8
import sys, os
sys.path.append(os.pardir)
import numpy as np
from dataset_straight.straight_dataset import load_mnist
import matplotlib.pyplot as plt
# データの読み込み
(x_train, t_train), (x_test, t_test) = load_mnist(normalize=False, one_hot_label=True)
fig = plt.figure()
fig.subplots_adjust(left=0, right=1, bottom=0, top=1, hspace=0.2, wspace=0.2)
current_view = 1
for i in range(first_offset, last_offset):
ax = fig.add_subplot(4, 5, current_view, xticks=[], yticks=[])
ax.imshow(x_test[i].reshape(10, 56), cmap=plt.cm.gray, interpolation='nearest')
current_view += 1
plt.show()
view_straight(1000, 1010)
# 白線追従走行用の画像データをCの配列に出力し、ファイルに書き込み
# image_data2c_wt.py
# coding: utf-8
import sys, os
sys.path.append(os.pardir)
import numpy as np
from dataset_straight.straight_dataset import load_mnist
import datetime
OUTPUT_DATA_NUM = 50 # 出力する白線追従走行のテストデータ数 直進、左旋回、右旋回で x 3
OFFSET = 0 # 白線追従走行用データセットのオフセット、100だったら100番目からOUTPUT_DATA_NUM個を出力する
def normal_image(offset, output_data_num, x_test, end):
for i in range(offset, offset+output_data_num):
f.write("\t{")
for j in range(x_test.shape[1]):
f.write(str(x_test[i][j]))
if (j==x_test.shape[1]-1):
if (i==offset+output_data_num-1 and end==1):
f.write("}\n")
else:
f.write("},\n")
else:
f.write(", ")
def no_normal_image(offset, output_data_num, x_test, end):
for i in range(offset, offset+output_data_num):
f.write("\t{")
for j in range(x_test.shape[1]):
f.write(str(int(x_test[i][j]*256)))
if (j==x_test.shape[1]-1):
if (i==offset+output_data_num-1 and end==1):
f.write("}\n")
else:
f.write("},\n")
else:
f.write(", ")
def normal_label(offset, output_data_num, t_test, end):
for i in range(offset, offset+output_data_num):
f.write("\t{")
for j in range(t_test.shape[1]):
f.write(str(t_test[i][j]))
if (j==t_test.shape[1]-1):
if (i==offset+output_data_num-1 and end==1):
f.write("}\n")
else:
f.write("},\n")
else:
f.write(", ")
# データの読み込み
(x_train, t_train), (x_test, t_test) = load_mnist(normalize=True, one_hot_label=True)
all_x_test = x_test.shape[0];
all_go_direction = int(all_x_test/3);
print(all_x_test)
print(all_go_direction)
f = open("straight_data.h", 'w')
todaytime = datetime.datetime.today()
f.write('// mnist_data.h\n')
strdtime = todaytime.strftime("%Y/%m/%d %H:%M:%S")
f.write('// {0} by marsee\n'.format(strdtime))
f.write("\n")
f.write('ap_ufixed<8, 0, AP_TRN_ZERO, AP_SAT> t_train['+str(OUTPUT_DATA_NUM*3)+']['+str(x_test.shape[1])+'] = {\n')
normal_image(OFFSET, OUTPUT_DATA_NUM, x_test, 0) # 直進
normal_image(OFFSET+all_go_direction, OUTPUT_DATA_NUM, x_test, 0) # 左旋回
normal_image(OFFSET+all_go_direction*2, OUTPUT_DATA_NUM, x_test, 1) # 右旋回
f.write("};\n")
f.write('int t_train_256['+str(OUTPUT_DATA_NUM*3)+']['+str(x_test.shape[1])+'] = {\n')
no_normal_image(OFFSET, OUTPUT_DATA_NUM, x_test, 0) # 直進
no_normal_image(OFFSET+all_go_direction, OUTPUT_DATA_NUM, x_test, 0) # 左旋回
no_normal_image(OFFSET+all_go_direction*2, OUTPUT_DATA_NUM, x_test, 1) # 右旋回
f.write("};\n")
f.write("\n")
f.write('float t_test['+str(OUTPUT_DATA_NUM*3)+']['+str(t_test.shape[1])+'] = {\n')
normal_label(OFFSET, OUTPUT_DATA_NUM, t_test, 0) # 直進
normal_label(OFFSET+all_go_direction, OUTPUT_DATA_NUM, t_test, 0) # 左旋回
normal_label(OFFSET+all_go_direction*2, OUTPUT_DATA_NUM, t_test, 1) # 右旋回
f.write("};\n")
f.close()
$xv_path/bin/xsc zynq_dpi.c 2>&1 | tee c_compile.log
// conv1_weight.h
// 2017/08/24 20:29:30 by marsee
const float conv1_fweight[2][1][5][5] =
{
{
{
{0.294570413175,0.494004676217,0.44994119544,0.515573789799,0.544610330831},
{0.40486488371,0.462682035597,0.45391988533,0.428258168527,0.380212999297},
{0.50351358146,0.495029433364,0.498244962825,0.433375033151,0.377243668748},
{0.503165711207,0.487963332866,0.444891841935,0.422814642144,0.401928034088},
{0.411021574202,0.418571893201,0.487229387082,0.491190313386,0.499503929646}
}
}
,
{
{
{0.00429091281128,-0.00429508065741,0.00521589342041,-0.00542417093149,0.0115336444712},
{-0.00520812977283,-0.0125367789506,-0.0165218053161,-0.00583519826402,0.0021076978354},
{0.0105605800117,-0.00306969245547,-0.0136611794413,-0.00504961598515,-0.0163449762107},
{-0.0086441958247,-0.00414093021477,-0.00716074872487,-0.00832960908688,-0.000113451640109},
{0.00463348666248,4.79973508012e-05,0.0139718435768,0.000123781195982,0.0105360722489}
}
}
};
const ap_fixed<9, 1, AP_TRN_ZERO, AP_SAT> conv1_weight[2][1][5][5] =
{
{
{
{0.29296875,0.4921875,0.44921875,0.515625,0.54296875},
{0.40625,0.4609375,0.453125,0.4296875,0.37890625},
{0.50390625,0.49609375,0.5,0.43359375,0.37890625},
{0.50390625,0.48828125,0.4453125,0.421875,0.40234375},
{0.41015625,0.41796875,0.48828125,0.4921875,0.5}
}
}
,
{
{
{0.00390625,0.0,0.00390625,0.0,0.01171875},
{0.0,-0.0078125,-0.01171875,0.0,0.00390625},
{0.01171875,0.0,-0.0078125,0.0,-0.01171875},
{-0.00390625,0.0,-0.00390625,-0.00390625,0.0},
{0.00390625,0.0,0.015625,0.0,0.01171875}
}
}
};
// conv1_bias.h
// 2017/08/24 20:29:33 by marsee
const float conv1_fbias[2] = {
-0.467403343047, 0.0
};
const ap_fixed<9, 1, AP_TRN_ZERO, AP_SAT> conv1_bias[2] = {
-0.46484375, 0.0
};
// af1_bias.h
// 2017/08/24 20:29:35 by marsee
const float af1_fbias[100] = {
-0.00538524705766, -0.00598539062265, -0.00565536048132, 0.0, -0.00685936102353, -0.00536698581278, -0.00623459442338, -0.00709394959053, 0.0, 0.158105182373, -0.034250223689, -0.00124515452719, 0.0, 0.156260635706, 0.0258001494218, 0.0844813437335, 0.0882019232825, -0.0703133823315, 0.0, -0.00528064880736, -0.00423357775603, -0.00599602018708, 0.0741511844097, -0.140380278179, -0.00802484293904, -0.00594926156475, 0.160366829792, -0.00598124395411, -0.00581691965127, 0.0, -0.00433641008826, -0.0581982793318, -0.00594840502984, 0.0, -0.00596392388605, -0.0345905812002, -0.00596700013907, 0.0, -0.00566465835073, 0.0, -0.00543342053868, 0.106799576721, 0.0416939154099, -0.0877609455334, 0.0572610067402, -0.00588865216287, -0.00598300886618, -0.119024744237, 0.0851440309957, 0.12963722794, -0.00806675185856, -0.00434584279575, 0.109825401931, 0.0, 0.0422327145024, -0.00592485633898, 0.0534250925738, -0.0559710722051, -0.00535198913464, -0.0059733490076, -0.0861017024054, -0.00588027805792, 0.00459288993198, 0.0, -0.00591545649515, 0.0897744436782, -0.0059229789071, -0.072504495188, -0.00523629719031, -0.00491575729656, -0.101839639745, 0.15618643854, -0.00562686983234, -0.00595156113069, -0.00532042799961, -0.00593544841409, 0.0, -0.145186356158, -0.00597335414762, 0.0, -0.00738509413214, 0.0868084556983, -0.00487009622847, -0.00590424120649, -0.00751997670017, -0.142521109799, 0.0, -0.0969972486866, -0.105567556471, -0.00595290267302, 0.0264242303548, -0.13445683226, -0.00747600747375, 0.0, 0.0, 0.0, -0.00597598643903, -0.152706252034, 0.0, -0.0660025441402
};
const ap_fixed<9, 1, AP_TRN_ZERO, AP_SAT> af1_bias[100] = {
0.0, -0.00390625, 0.0, 0.0, -0.00390625, 0.0, -0.00390625, -0.00390625, 0.0, 0.15625, -0.03125, 0.0, 0.0, 0.15625, 0.02734375, 0.0859375, 0.08984375, -0.06640625, 0.0, 0.0, 0.0, -0.00390625, 0.07421875, -0.13671875, -0.00390625, -0.00390625, 0.16015625, -0.00390625, 0.0, 0.0, 0.0, -0.0546875, -0.00390625, 0.0, -0.00390625, -0.03125, -0.00390625, 0.0, 0.0, 0.0, 0.0, 0.10546875, 0.04296875, -0.08203125, 0.05859375, -0.00390625, -0.00390625, -0.11328125, 0.0859375, 0.12890625, -0.00390625, 0.0, 0.109375, 0.0, 0.04296875, -0.00390625, 0.0546875, -0.05078125, 0.0, -0.00390625, -0.08203125, -0.00390625, 0.00390625, 0.0, -0.00390625, 0.08984375, -0.00390625, -0.0703125, 0.0, 0.0, -0.09765625, 0.15625, 0.0, -0.00390625, 0.0, -0.00390625, 0.0, -0.140625, -0.00390625, 0.0, -0.00390625, 0.0859375, 0.0, -0.00390625, -0.00390625, -0.13671875, 0.0, -0.09375, -0.1015625, -0.00390625, 0.02734375, -0.12890625, -0.00390625, 0.0, 0.0, 0.0, -0.00390625, -0.1484375, 0.0, -0.0625
};
// af2_weight.h
// 2017/08/24 20:29:38 by marsee
const float af2_fweight[100][3] = {
{-0.00820355970957, 0.00101259251505, -0.00738029792378},
{-0.00658775205594, -0.00486606234669, -0.0093604152744},
{-0.00376509576185, -0.00320418156839, 0.00446600986062},
{-0.00222591145973, -0.0114764282693, -0.0125846717219},
{-0.0172525876603, -0.0121569822688, -0.0174832203182},
{-0.00444121247093, 0.00376660670372, 0.00494277572638},
{0.0144166341511, 0.00571422646049, -0.000451331284046},
{-0.00773734700282, -0.0127894700042, -0.00316662283778},
{-0.00980320311497, 0.00774144449332, 0.00466787755531},
{-0.15322396644, 0.00832043391883, 0.201276629574},
{-0.0673021200462, 0.090204938319, -0.112073644712},
{0.00298307464543, 0.00644157245156, 0.00800343766018},
{-0.00952199361278, -0.00483905084921, -0.0150083862732},
{-0.100111162346, -0.0667418921018, 0.168230912865},
{-0.434389531817, 0.122761868388, 0.112380800074},
{-0.185556538957, 0.117074098232, -0.00454780154485},
{-0.208130927894, 0.128148635127, 0.00580676863725},
{0.00536293527661, 0.110961879853, -0.200961349249},
{0.0179132482975, 0.000113803245086, -0.0179738854863},
{0.0078521915451, 0.00490887162668, 0.00664359090093},
{0.00279295320522, -0.0117809816332, 0.0233511027877},
{0.00576400892566, -0.00154713969962, 0.00780394968406},
{0.0326806385735, -0.116272360744, 0.104181499231},
{0.281688127519, -0.050505987361, -0.337821332905},
{0.00412715457262, 0.00528169945268, 0.00765624887698},
{-0.000676362650949, -0.00621588362489, 0.0114413980656},
{-0.152045040818, -0.0197797439475, 0.176308752788},
{-0.00101985599932, -0.007261180072, -0.00405065562585},
{-0.0109482777895, 0.00296508846956, 0.00209693843146},
{-0.00941176993216, -0.0150338639802, 0.0146204542805},
{0.0108765000503, 0.00221551292604, -0.00943386328304},
{0.273536715663, -0.439966649596, -0.0483120039363},
{0.000641385899579, 0.00176874518582, -0.00283284521959},
{-0.0114604863243, -0.00768064077955, -0.0105853713444},
{0.00367602592519, -0.0201054399855, -0.00727753876315},
{0.130101479837, -0.128414436101, 0.0249145199096},
{-0.000823341887256, 0.0101337481958, 0.00650373443506},
{-0.00943068902902, -0.00153673986995, -0.00636511125021},
{0.00756524681284, -0.000957146481434, 0.00279509536095},
{-0.0101610421199, -0.0121689094742, 0.00611739537186},
{0.0027751740864, 0.000687300479967, -0.00142426431398},
{0.0107963370449, -0.0961563198848, 0.135769397739},
{0.067479675116, -0.118680921462, 0.101454270851},
{0.278649405523, -0.0638102974619, -0.405159676297},
{-0.159282176171, 0.120383212282, -0.0300551862799},
{0.0136189888263, 0.00592176212131, 0.00672759183286},
{0.0137818559794, 0.0163873393378, 0.00642866861232},
{0.282523857349, -0.087944438418, -0.238954778183},
{-0.190255947702, 0.145579608359, 0.0075601932195},
{-0.0315043857812, -0.083623000309, 0.136702205578},
{0.000608033306684, 0.00913886457474, 0.0102832249771},
{0.00537688751525, 0.0133161346686, 0.00610052322048},
{-0.234663551893, 0.124274954421, 0.0563793991797},
{0.00587731057438, -0.0158664237682, 0.0284369610688},
{-0.543641163625, 0.130027365245, 0.157524888611},
{-0.00774212606919, -0.00450843332955, 0.0189166493825},
{0.0646963727477, -0.10805031613, 0.108404665099},
{-0.0267923571638, 0.108829036939, -0.121159157504},
{-0.0184022178486, 0.0169815640108, 0.0154621580396},
{0.00290301989998, 0.00439110305282, 0.0129160123658},
{0.295774852423, -0.0564873278638, -0.537593080117},
{-0.00117304650041, 0.0106191567221, 0.00614773011635},
{0.00185660062042, -0.00336154769079, -0.00131980922298},
{0.000711758901132, -0.0169497734151, 0.00983303319272},
{0.0116480430004, 0.00521583788765, 0.0111912428732},
{-0.19337006872, 0.112667172799, 0.004643172569},
{0.00538846297219, 0.00584099064517, -0.00176371930271},
{-0.0270590458883, 0.111207364222, -0.13031455024},
{-0.00639778743806, 0.0167466500488, 0.00998962984116},
{-0.0124290681965, 0.000692885600751, -0.00959108577132},
{0.388707026472, -0.490774843687, -0.113918271156},
{-0.160369252488, -0.000791160018629, 0.170142601415},
{0.00327790299305, 0.012957827668, 0.0128847095396},
{0.00131031872257, -0.000112629890535, -0.00291128770448},
{0.101561554831, -0.110522196234, 0.063784932396},
{-0.00458738838876, -0.00859014309809, -0.00576967017053},
{0.00594556455932, 0.00568700357997, 0.00436139354229},
{0.277537764075, 0.0147263855709, -0.325946679767},
{0.00281375861934, 0.00683218489034, 0.00312772971751},
{-0.0189692725335, 0.0069368813551, -0.000677285718001},
{0.00786093523784, -0.000952448132357, -0.013087215922},
{0.0424404088819, -0.1109270947, 0.13765443958},
{0.00663733102854, -0.0122406089112, 0.00238680007741},
{0.00335383990373, 0.0116474058589, 0.01331781551},
{0.00631725835386, -0.0058431887138, -0.00040914131858},
{0.308370395049, -0.0440874511783, -0.366299602116},
{-0.0149362582815, 0.00446126933178, -0.000938738496254},
{0.184354359182, -0.0904720145049, -0.0866392911745},
{0.193741093433, -0.0876960948411, -0.113986496103},
{-0.0249647325112, -0.00594280295746, 0.01038246304},
{0.0850977285604, -0.115515891977, 0.0909139518915},
{0.260905844821, -0.0841269913801, -0.317866350456},
{-0.00097223996393, -0.0046818354073, -0.00443646653402},
{-0.00364175454929, 0.0139558811565, -0.00771410003344},
{-0.00216841359756, -0.00545245263308, -0.00386304728375},
{-8.70602913003e-05, 0.0111431740564, 0.0145401735664},
{-0.00963447070917, -0.00778226960809, 0.00101368004201},
{0.250679110641, 0.0187397414502, -0.326182991553},
{-0.0139841946077, 0.00711648201795, 0.0103306514814},
{0.18164313447, -0.133722739697, -0.00864408506204}
};
const ap_fixed<9, 1, AP_TRN_ZERO, AP_SAT> af2_weight[100][3] = {
{-0.00390625, 0.0, -0.00390625},
{-0.00390625, 0.0, -0.00390625},
{0.0, 0.0, 0.00390625},
{0.0, -0.0078125, -0.0078125},
{-0.01171875, -0.0078125, -0.01171875},
{0.0, 0.00390625, 0.00390625},
{0.015625, 0.00390625, 0.0},
{-0.00390625, -0.0078125, 0.0},
{-0.0078125, 0.0078125, 0.00390625},
{-0.1484375, 0.0078125, 0.203125},
{-0.0625, 0.08984375, -0.109375},
{0.00390625, 0.0078125, 0.0078125},
{-0.00390625, 0.0, -0.01171875},
{-0.09765625, -0.0625, 0.16796875},
{-0.4296875, 0.12109375, 0.11328125},
{-0.18359375, 0.1171875, 0.0},
{-0.203125, 0.12890625, 0.00390625},
{0.00390625, 0.109375, -0.1953125},
{0.01953125, 0.0, -0.015625},
{0.0078125, 0.00390625, 0.0078125},
{0.00390625, -0.0078125, 0.0234375},
{0.00390625, 0.0, 0.0078125},
{0.03125, -0.11328125, 0.10546875},
{0.28125, -0.046875, -0.33203125},
{0.00390625, 0.00390625, 0.0078125},
{0.0, -0.00390625, 0.01171875},
{-0.1484375, -0.015625, 0.17578125},
{0.0, -0.00390625, 0.0},
{-0.0078125, 0.00390625, 0.00390625},
{-0.00390625, -0.01171875, 0.015625},
{0.01171875, 0.00390625, -0.00390625},
{0.2734375, -0.4375, -0.04296875},
{0.0, 0.0, 0.0},
{-0.0078125, -0.00390625, -0.0078125},
{0.00390625, -0.015625, -0.00390625},
{0.12890625, -0.125, 0.0234375},
{0.0, 0.01171875, 0.0078125},
{-0.00390625, 0.0, -0.00390625},
{0.0078125, 0.0, 0.00390625},
{-0.0078125, -0.0078125, 0.0078125},
{0.00390625, 0.0, 0.0},
{0.01171875, -0.09375, 0.13671875},
{0.06640625, -0.11328125, 0.1015625},
{0.27734375, -0.05859375, -0.40234375},
{-0.15625, 0.12109375, -0.02734375},
{0.01171875, 0.0078125, 0.0078125},
{0.015625, 0.015625, 0.0078125},
{0.28125, -0.0859375, -0.234375},
{-0.1875, 0.14453125, 0.0078125},
{-0.02734375, -0.078125, 0.13671875},
{0.0, 0.0078125, 0.01171875},
{0.00390625, 0.01171875, 0.0078125},
{-0.23046875, 0.125, 0.0546875},
{0.0078125, -0.01171875, 0.02734375},
{-0.5390625, 0.12890625, 0.15625},
{-0.00390625, 0.0, 0.01953125},
{0.06640625, -0.10546875, 0.109375},
{-0.0234375, 0.109375, -0.1171875},
{-0.015625, 0.015625, 0.015625},
{0.00390625, 0.00390625, 0.01171875},
{0.296875, -0.05078125, -0.53515625},
{0.0, 0.01171875, 0.0078125},
{0.0, 0.0, 0.0},
{0.0, -0.01171875, 0.01171875},
{0.01171875, 0.00390625, 0.01171875},
{-0.19140625, 0.11328125, 0.00390625},
{0.00390625, 0.00390625, 0.0},
{-0.0234375, 0.109375, -0.125},
{-0.00390625, 0.015625, 0.01171875},
{-0.0078125, 0.0, -0.00390625},
{0.390625, -0.48828125, -0.109375},
{-0.15625, 0.0, 0.171875},
{0.00390625, 0.01171875, 0.01171875},
{0.0, 0.0, 0.0},
{0.1015625, -0.10546875, 0.0625},
{0.0, -0.00390625, 0.0},
{0.0078125, 0.00390625, 0.00390625},
{0.27734375, 0.015625, -0.3203125},
{0.00390625, 0.0078125, 0.00390625},
{-0.015625, 0.0078125, 0.0},
{0.0078125, 0.0, -0.0078125},
{0.04296875, -0.10546875, 0.13671875},
{0.0078125, -0.0078125, 0.00390625},
{0.00390625, 0.01171875, 0.01171875},
{0.0078125, 0.0, 0.0},
{0.30859375, -0.0390625, -0.36328125},
{-0.01171875, 0.00390625, 0.0},
{0.18359375, -0.0859375, -0.08203125},
{0.1953125, -0.08203125, -0.109375},
{-0.01953125, -0.00390625, 0.01171875},
{0.0859375, -0.11328125, 0.08984375},
{0.26171875, -0.08203125, -0.3125},
{0.0, 0.0, 0.0},
{0.0, 0.015625, -0.00390625},
{0.0, 0.0, 0.0},
{0.0, 0.01171875, 0.015625},
{-0.00390625, -0.00390625, 0.0},
{0.25, 0.01953125, -0.32421875},
{-0.01171875, 0.0078125, 0.01171875},
{0.18359375, -0.12890625, -0.00390625}
};
// af2_bias.h
// 2017/08/24 20:29:35 by marsee
const float af2_fbias[3] = {
-0.0999304880919, -0.0287908286804, 0.121076044953
};
const ap_fixed<9, 1, AP_TRN_ZERO, AP_SAT> af2_bias[3] = {
-0.09765625, -0.0234375, 0.12109375
};
(100, 1, 10, 56)
Conv col.shape = (31200, 25)
Conv col_W.shape = (25, 2)
Conv np.max(x) = 0.9686274528503418
Conv np.min(x) = 0.29411765933036804
(2, 1, 5, 5)
Conv np.max(self.W_int) = 0.54296875
Conv np.min(self.W_int) = -0.01171875
(2,)
Conv np.max(self.b_int) = 0.0
Conv np.min(self.b_int) = -0.46484375
Conv out.shape = (31200, 2)
Conv np.max(out) = 10.408639731584117
Conv np.min(out) = 0.00032169173937290907
Conv np.max(out2) = 10.4375
Conv np.min(out2) = 0.0
Conv out.reshape = (100, 2, 6, 52)
Pooling x.shape = (100, 2, 6, 52)
Pooling out.shape = (100, 2, 3, 26)
x shape =(100, 2, 3, 26)
np.max(self.W) = 0.3530595475749049
np.max(self.W) = 0.3530595475749049
np.max(self.b) = 0.16036682979180678
x reshape =(100, 156)
np.max(x) = 10.4375
np.min(x) = 0.0
(156, 100)
np.max(self.W_int) = 0.3515625
np.min(self.W_int) = -0.3046875
(100,)
np.max(self.b_int) = 0.16015625
np.min(self.b_int) = -0.1484375
(100, 100)
np.max(out) = 8.645263671875
np.min(out) = -4.50537109375
np.max(out2) = 8.65625
np.min(out2) = -4.46875
x shape =(100, 100)
np.max(self.W) = 0.38870702647190525
np.max(self.W) = 0.38870702647190525
np.max(self.b) = 0.12107604495322784
x reshape =(100, 100)
np.max(x) = 8.65625
np.min(x) = 0.0
(100, 3)
np.max(self.W_int) = 0.390625
np.min(self.W_int) = -0.5390625
(3,)
np.max(self.b_int) = 0.12109375
np.min(self.b_int) = -0.09765625
(100, 3)
np.max(out) = 7.540771484375
np.min(out) = -8.2576904296875
np.max(out2) = 7.53125
np.min(out2) = -8.21875
直線走行CONV_NNのCONV数とmax_epochsによる精度の違い
トレーニング画像数9075、テスト画像数4125
CONV=30, max_epochs = 10
pool_output_size =2340
test acc:0.854545454545
CONV=30, max_epochs = 20
test acc:0.888
CONV=30, max_epochs = 40
test acc:0.875636363636
CONV=30, max_epochs = 60
test acc:0.843636363636
CONV=30, max_epochs = 80
test acc:0.877575757576
CONV=10, max_epochs = 10
pool_output_size =780
test acc:0.941333333333
CONV=10, max_epochs = 20
test acc:0.931878787879
CONV=10, max_epochs = 40
test acc:0.900121212121
CONV=10, max_epochs = 60
test acc:0.868848484848
CONV=10, max_epochs = 80
test acc:0.881454545455
CONV=8, max_epochs = 10
pool_output_size =624
test acc:0.900363636364
CONV=8, max_epochs = 20
test acc:0.908606060606
CONV=8, max_epochs = 40
test acc:0.919515151515
CONV=6, max_epochs = 10
pool_output_size =468
test acc:0.882666666667
CONV=6, max_epochs = 20
test acc:0.923151515152
CONV=6, max_epochs = 40
test acc:0.901818181818
CONV=12, max_epochs = 10
pool_output_size =936
test acc:0.938424242424
CONV=14, max_epochs = 10
pool_output_size =1092
test acc:0.900848484848
CONV=16, max_epochs = 10
pool_output_size =1248
test acc:0.955151515152
CONV=18, max_epochs = 10
pool_output_size =1404
test acc:0.930666666667
CONV=20, max_epochs = 10
pool_output_size =1560
test acc:0.935272727273
CONV=22, max_epochs = 10
pool_output_size =1716
test acc:0.928
CONV=24, max_epochs = 10
pool_output_size =1872
test acc:0.843393939394
CONV=26, max_epochs = 10
pool_output_size =2028
test acc:0.922181818182
CONV=28, max_epochs = 10
pool_output_size =2184
test acc:0.914666666667
CONV=4, max_epochs = 10
pool_output_size =312
test acc:0.889696969697
CONV=4, max_epochs = 20
test acc:0.933575757576
CONV=4, max_epochs = 40
test acc:0.908363636364
CONV=3, max_epochs = 10
pool_output_size =234
test acc:0.837090909091
CONV=3, max_epochs = 20
test acc:0.918545454545
CONV=3, max_epochs = 40
test acc:0.879515151515
CONV=2, max_epochs = 10
pool_output_size =156
test acc:0.922181818182
CONV=2, max_epochs = 20
test acc:0.947878787879
CONV=2, max_epochs = 40
test acc:0.895272727273
#!/bin/bash
# increase_image_test
# for test
max=5
# contrast
for ((i=0; i < $max; i++)); do
convert left_turn_test$i.bmp -contrast left_turn_test$(expr $i + $max).bmp
convert right_turn_test$i.bmp -contrast right_turn_test$(expr $i + $max).bmp
convert straight_test$i.bmp -contrast straight_test$(expr $i + $max).bmp
done
for ((i=0; i < $max; i++)); do
convert left_turn_test$i.bmp -contrast -contrast left_turn_test$(expr $i + $max \* 2).bmp
convert right_turn_test$i.bmp -contrast -contrast right_turn_test$(expr $i + $max \* 2).bmp
convert straight_test$i.bmp -contrast -contrast straight_test$(expr $i + $max \* 2).bmp
done
for ((i=0; i < $max; i++)); do
convert left_turn_test$i.bmp -contrast -contrast -contrast left_turn_test$(expr $i + $max \* 3).bmp
convert right_turn_test$i.bmp -contrast -contrast -contrast right_turn_test$(expr $i + $max \* 3).bmp
convert straight_test$i.bmp -contrast -contrast -contrast straight_test$(expr $i + $max \* 3).bmp
done
for ((i=0; i < $max; i++)); do
convert left_turn_test$i.bmp +contrast left_turn_test$(expr $i + $max \* 4).bmp
convert right_turn_test$i.bmp +contrast right_turn_test$(expr $i + $max \* 4).bmp
convert straight_test$i.bmp +contrast straight_test$(expr $i + $max \* 4).bmp
done
for ((i=0; i < $max; i++)); do
convert left_turn_test$i.bmp +contrast +contrast left_turn_test$(expr $i + $max \* 5).bmp
convert right_turn_test$i.bmp +contrast +contrast right_turn_test$(expr $i + $max \* 5).bmp
convert straight_test$i.bmp +contrast +contrast straight_test$(expr $i + $max \* 5).bmp
done
for ((i=0; i < $max; i++)); do
convert left_turn_test$i.bmp +contrast +contrast +contrast left_turn_test$(expr $i + $max \* 6).bmp
convert right_turn_test$i.bmp +contrast +contrast +contrast right_turn_test$(expr $i + $max \* 6).bmp
convert straight_test$i.bmp +contrast +contrast +contrast straight_test$(expr $i + $max \* 6).bmp
done
# blur
for ((i=0; i < $max; i++)); do
convert left_turn_test$i.bmp -blur 10x1.5 left_turn_test$(expr $i + $max \* 7).bmp
convert right_turn_test$i.bmp -blur 10x1.5 right_turn_test$(expr $i + $max \* 7).bmp
convert straight_test$i.bmp -blur 10x1.5 straight_test$(expr $i + $max \* 7).bmp
done
for ((i=0; i < $max; i++)); do
convert left_turn_test$i.bmp -blur 10x2 left_turn_test$(expr $i + $max \* 8).bmp
convert right_turn_test$i.bmp -blur 10x2 right_turn_test$(expr $i + $max \* 8).bmp
convert straight_test$i.bmp -blur 10x2 straight_test$(expr $i + $max \* 8).bmp
done
#gamma
for ((i=0; i < $max; i++)); do
convert left_turn_test$i.bmp -gamma 1.5 left_turn_test$(expr $i + $max \* 9).bmp
convert right_turn_test$i.bmp -gamma 1.5 right_turn_test$(expr $i + $max \* 9).bmp
convert straight_test$i.bmp -gamma 1.5 straight_test$(expr $i + $max \* 9).bmp
done
for ((i=0; i < $max; i++)); do
convert left_turn_test$i.bmp -gamma 0.75 left_turn_test$(expr $i + $max \* 10).bmp
convert right_turn_test$i.bmp -gamma 0.75 right_turn_test$(expr $i + $max \* 10).bmp
convert straight_test$i.bmp -gamma 0.75 straight_test$(expr $i + $max \* 10).bmp
done
// straight_dataset_bmp_nowr.cpp
// 2017/07/24 by marsee
//
// 2017/08/21 : no write bmp files
//
#include <iostream>
#include "hls_opencv.h"
#include "straight_dataset_bmp.h"
#include <arpa/inet.h>
const char IMAGE_DIR[] = "train_data_170808";
int main(){
char straight_fn[256] = "straight";
char left_turn_fn[256] = "left_turn";
char right_turn_fn[256] = "right_turn";
char bmp_file[256];
FILE *ftin, *ftln;
char train_image_name[256] = "train_straight_run_image";
char train_label_name[256] = "train_straight_run_label";
uint32_t buf[5];
uint8_t bufchar[100];
if ((ftin = fopen(train_image_name, "wb")) == NULL){
fprintf(stderr, "Can't open %s\n", train_image_name);
exit(1);
}
if ((ftln = fopen(train_label_name, "wb")) == NULL){
fprintf(stderr, "Can't open %s\n", train_label_name);
exit(1);
}
// Writed header
buf[0] = htonl(0x803); // magic number
buf[1] = htonl((STRAIGHT_NUM_OF_IMAGE+LEFT_TRUN_NUM_OF_IMAGE+RIGHT_TRUNNUM_OF_IMAGE)*25); // number of image
buf[2] = htonl(10); // number of rows (10)
buf[3] = htonl(56); // number of columns (56)
fwrite(buf, sizeof(uint32_t), 4, ftin);
buf[0] = htonl(0x801); // magic number
buf[1] = htonl((STRAIGHT_NUM_OF_IMAGE+LEFT_TRUN_NUM_OF_IMAGE+RIGHT_TRUNNUM_OF_IMAGE)*25); // number of image
fwrite(buf, sizeof(uint32_t), 2, ftln);
// refereed to http://opencv.jp/cookbook/opencv_img.html
// straight
for(int i=0; i<STRAIGHT_NUM_OF_IMAGE; i++){
sprintf(bmp_file, "%s/%s%d.bmp", IMAGE_DIR, straight_fn, i);
cv::Mat straight_img = cv::imread(bmp_file,1);
if(straight_img.empty())
return(-1);
cv::Mat reduct_img(straight_img.rows*0.075, straight_img.cols*0.075, straight_img.type());
cv::resize(straight_img, reduct_img, reduct_img.size(), cv::INTER_LINEAR);
cv::Mat gray_img;
cv::cvtColor(reduct_img, gray_img, CV_BGR2GRAY);
//sprintf(bmp_file, "%s_RED%d.bmp", straight_fn, i);
//cv::imwrite(bmp_file, gray_img);
for(int y=0; y<5; y++){
for(int x=0; x<5; x++){
cv::Rect rect_center(x, 30+y, 56, 10);
cv::Mat img_rect(gray_img, rect_center);
//sprintf(bmp_file, "%s_RED_rect%d_%d%d.bmp", straight_fn, i, y, x);
//cv::imwrite(bmp_file, img_rect);
for(int iy=0; iy<img_rect.rows; iy++){
for(int ix=0; ix<img_rect.cols; ix++){
bufchar[ix] = img_rect.at<uchar>(iy, ix);
}
fwrite(bufchar, sizeof(uint8_t), img_rect.cols, ftin); // image write
}
bufchar[0] = 0x1;
fwrite(bufchar, sizeof(uint8_t), 1, ftln); // label write
}
}
}
// left turn
for(int i=0; i<LEFT_TRUN_NUM_OF_IMAGE; i++){
sprintf(bmp_file, "%s/%s%d.bmp", IMAGE_DIR, left_turn_fn, i);
cv::Mat left_trun_img = cv::imread(bmp_file,1);
if(left_trun_img.empty())
return(-1);
cv::Mat reduct_img(left_trun_img.rows*0.075, left_trun_img.cols*0.075, left_trun_img.type());
cv::resize(left_trun_img, reduct_img, reduct_img.size(), cv::INTER_LINEAR);
cv::Mat gray_img;
cv::cvtColor(reduct_img, gray_img, CV_BGR2GRAY);
//sprintf(bmp_file, "%s_RED%d.bmp", left_turn_fn, i);
//cv::imwrite(bmp_file, gray_img);
for(int y=0; y<5; y++){
for(int x=0; x<5; x++){
cv::Rect rect_center(x, 30+y, 56, 10);
cv::Mat img_rect(gray_img, rect_center);
//sprintf(bmp_file, "%s_RED_rect%d_%d%d.bmp", left_turn_fn, i, y, x);
//cv::imwrite(bmp_file, img_rect);
for(int iy=0; iy<img_rect.rows; iy++){
for(int ix=0; ix<img_rect.cols; ix++){
bufchar[ix] = img_rect.at<uchar>(iy, ix);
}
fwrite(bufchar, sizeof(uint8_t), img_rect.cols, ftin); // image write
}
bufchar[0] = 0x0;
fwrite(bufchar, sizeof(uint8_t), 1, ftln); // label write
}
}
}
// right turn
for(int i=0; i<STRAIGHT_NUM_OF_IMAGE; i++){
sprintf(bmp_file, "%s/%s%d.bmp", IMAGE_DIR, right_turn_fn, i);
cv::Mat right_trun_img = cv::imread(bmp_file,1);
if(right_trun_img.empty())
return(-1);
cv::Mat reduct_img(right_trun_img.rows*0.075, right_trun_img.cols*0.075, right_trun_img.type());
cv::resize(right_trun_img, reduct_img, reduct_img.size(), cv::INTER_LINEAR);
cv::Mat gray_img;
cv::cvtColor(reduct_img, gray_img, CV_BGR2GRAY);
//sprintf(bmp_file, "%s_RED%d.bmp", right_turn_fn, i);
//cv::imwrite(bmp_file, gray_img);
for(int y=0; y<5; y++){
for(int x=0; x<5; x++){
cv::Rect rect_center(x, 30+y, 56, 10);
cv::Mat img_rect(gray_img, rect_center);
//sprintf(bmp_file, "%s_RED_rect%d_%d%d.bmp", right_turn_fn, i, y, x);
//cv::imwrite(bmp_file, img_rect);
for(int iy=0; iy<img_rect.rows; iy++){
for(int ix=0; ix<img_rect.cols; ix++){
bufchar[ix] = img_rect.at<uchar>(iy, ix);
}
fwrite(bufchar, sizeof(uint8_t), img_rect.cols, ftin); // image write
}
bufchar[0] = 0x2;
fwrite(bufchar, sizeof(uint8_t), 1, ftln); // label write
}
}
}
fclose(ftin);
fclose(ftln);
return(0);
}
#!/bin/bash
# increase_image
max=11
# contrast
for ((i=0; i < $max; i++)); do
convert left_turn$i.bmp -contrast left_turn$(expr $i + $max).bmp
convert right_turn$i.bmp -contrast right_turn$(expr $i + $max).bmp
convert straight$i.bmp -contrast straight$(expr $i + $max).bmp
done
for ((i=0; i < $max; i++)); do
convert left_turn$i.bmp -contrast -contrast left_turn$(expr $i + $max \* 2).bmp
convert right_turn$i.bmp -contrast -contrast right_turn$(expr $i + $max \* 2).bmp
convert straight$i.bmp -contrast -contrast straight$(expr $i + $max \* 2).bmp
done
for ((i=0; i < $max; i++)); do
convert left_turn$i.bmp -contrast -contrast -contrast left_turn$(expr $i + $max \* 3).bmp
convert right_turn$i.bmp -contrast -contrast -contrast right_turn$(expr $i + $max \* 3).bmp
convert straight$i.bmp -contrast -contrast -contrast straight$(expr $i + $max \* 3).bmp
done
for ((i=0; i < $max; i++)); do
convert left_turn$i.bmp +contrast left_turn$(expr $i + $max \* 4).bmp
convert right_turn$i.bmp +contrast right_turn$(expr $i + $max \* 4).bmp
convert straight$i.bmp +contrast straight$(expr $i + $max \* 4).bmp
done
for ((i=0; i < $max; i++)); do
convert left_turn$i.bmp +contrast +contrast left_turn$(expr $i + $max \* 5).bmp
convert right_turn$i.bmp +contrast +contrast right_turn$(expr $i + $max \* 5).bmp
convert straight$i.bmp +contrast +contrast straight$(expr $i + $max \* 5).bmp
done
for ((i=0; i < $max; i++)); do
convert left_turn$i.bmp +contrast +contrast +contrast left_turn$(expr $i + $max \* 6).bmp
convert right_turn$i.bmp +contrast +contrast +contrast right_turn$(expr $i + $max \* 6).bmp
convert straight$i.bmp +contrast +contrast +contrast straight$(expr $i + $max \* 6).bmp
done
# blur
for ((i=0; i < $max; i++)); do
convert left_turn$i.bmp -blur 10x1.5 left_turn$(expr $i + $max \* 7).bmp
convert right_turn$i.bmp -blur 10x1.5 right_turn$(expr $i + $max \* 7).bmp
convert straight$i.bmp -blur 10x1.5 straight$(expr $i + $max \* 7).bmp
done
for ((i=0; i < $max; i++)); do
convert left_turn$i.bmp -blur 10x2 left_turn$(expr $i + $max \* 8).bmp
convert right_turn$i.bmp -blur 10x2 right_turn$(expr $i + $max \* 8).bmp
convert straight$i.bmp -blur 10x2 straight$(expr $i + $max \* 8).bmp
done
#gamma
for ((i=0; i < $max; i++)); do
convert left_turn$i.bmp -gamma 1.5 left_turn$(expr $i + $max \* 9).bmp
convert right_turn$i.bmp -gamma 1.5 right_turn$(expr $i + $max \* 9).bmp
convert straight$i.bmp -gamma 1.5 straight$(expr $i + $max \* 9).bmp
done
for ((i=0; i < $max; i++)); do
convert left_turn$i.bmp -gamma 0.75 left_turn$(expr $i + $max \* 10).bmp
convert right_turn$i.bmp -gamma 0.75 right_turn$(expr $i + $max \* 10).bmp
convert straight$i.bmp -gamma 0.75 straight$(expr $i + $max \* 10).bmp
done
pool_output_size =2340
train loss:1.09597077527
=== epoch:1, train acc:0.0, test acc:0.0 ===
train loss:1.09763818641
train loss:1.09825520224
train loss:1.09830713311
train loss:1.09483577203
train loss:1.09673085529
train loss:1.09591664135
train loss:1.09249280974
train loss:1.08987641387
train loss:1.08545885042
train loss:1.08117723144
train loss:1.08097061845
train loss:1.06785401247
train loss:1.06847091152
train loss:1.07555744076
train loss:1.04351469112
train loss:1.04435821276
train loss:1.03649227153
train loss:1.02536538003
train loss:1.00731901572
train loss:0.994094999178
train loss:0.973141656596
train loss:0.970560099646
train loss:0.925359858257
train loss:0.922232065606
train loss:0.890463657306
train loss:0.857971776813
train loss:0.808963625972
train loss:0.810114333796
train loss:0.790134792491
train loss:0.75177290901
train loss:0.719148569532
train loss:0.703947163294
train loss:0.733538828557
=== epoch:2, train acc:1.0, test acc:0.97 ===
train loss:0.626812813265
train loss:0.691149885713
train loss:0.652269563466
train loss:0.551628036238
train loss:0.573457780284
train loss:0.555262535477
train loss:0.569233568195
train loss:0.608432180822
train loss:0.576392359819
train loss:0.553962266041
train loss:0.631553098995
train loss:0.541951265715
train loss:0.59235235809
train loss:0.570984798898
train loss:0.618629636193
train loss:0.519372445675
train loss:0.528735330839
train loss:0.484056856152
train loss:0.536815249815
train loss:0.561484523189
train loss:0.623591206274
train loss:0.442553097887
train loss:0.631538407003
train loss:0.543256943224
train loss:0.571884326854
train loss:0.59330093491
train loss:0.543568052814
train loss:0.625170917522
train loss:0.609623989829
train loss:0.626034861444
train loss:0.53018319314
train loss:0.478202730277
train loss:0.519885098008
=== epoch:3, train acc:1.0, test acc:0.79 ===
train loss:0.547483270221
train loss:0.645673557139
train loss:0.522337685379
train loss:0.536177468441
train loss:0.468486580763
train loss:0.515871224274
train loss:0.457075387848
train loss:0.398502113575
train loss:0.547250552889
train loss:0.47266059459
train loss:0.58253528562
train loss:0.563849158638
train loss:0.584245273642
train loss:0.490038949342
train loss:0.575957945909
train loss:0.53032895386
train loss:0.598642706188
train loss:0.51896606919
train loss:0.447935727928
train loss:0.523748197354
train loss:0.630220932465
train loss:0.475171119124
train loss:0.552545002799
train loss:0.418398639435
train loss:0.54651784985
train loss:0.54795133755
train loss:0.484632026785
train loss:0.486523131145
train loss:0.608954877859
train loss:0.52597657247
train loss:0.550768419421
train loss:0.510231459765
train loss:0.514870472085
=== epoch:4, train acc:1.0, test acc:0.86 ===
train loss:0.554327599733
train loss:0.476852300198
train loss:0.528736145907
train loss:0.431610455794
train loss:0.492618692268
train loss:0.523164350434
train loss:0.583515316911
train loss:0.456262940166
train loss:0.385874800448
train loss:0.391292082306
train loss:0.493916291898
train loss:0.469376182458
train loss:0.511861331662
train loss:0.555790656279
train loss:0.552997199476
train loss:0.491419451075
train loss:0.427534856105
train loss:0.462498766512
train loss:0.671785632209
train loss:0.674157815366
train loss:0.508518571047
train loss:0.454157308456
train loss:0.588429704378
train loss:0.539304639676
train loss:0.461259212557
train loss:0.439467592743
train loss:0.486391964423
train loss:0.541361700557
train loss:0.765172284665
train loss:0.557673416383
train loss:0.472034860108
train loss:0.467462631341
train loss:0.473195698334
=== epoch:5, train acc:0.94, test acc:0.63 ===
train loss:0.621301963466
train loss:0.519214259086
train loss:0.592548430631
train loss:0.44266943545
train loss:0.418137479978
train loss:0.458057503538
train loss:0.487746201447
train loss:0.542828607541
train loss:0.412820783943
train loss:0.387734335894
train loss:0.504347603465
train loss:0.372213430157
train loss:0.566137812809
train loss:0.511320738505
train loss:0.372290661458
train loss:0.43099129379
train loss:0.446050407765
train loss:0.580177285636
train loss:0.521574375012
train loss:0.470257839398
train loss:0.358914879585
train loss:0.429000331704
train loss:0.532481848172
train loss:0.487614622413
train loss:0.512510956562
train loss:0.443207619531
train loss:0.453973643453
train loss:0.527084108842
train loss:0.411040275113
train loss:0.514922929244
train loss:0.440648980547
train loss:0.521523873667
=============== Final Test Accuracy ===============
test acc:0.701333333333
Saved Network Parameters!
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-1-2cecdfeafa8d> in <module>()
39 markers = {'train': 'o', 'test': 's'}
40 x = np.arange(max_epochs)
---> 41 plt.plot(x, trainer.train_acc_list, marker='o', label='train', markevery=2)
42 plt.plot(x, trainer.test_acc_list, marker='s', label='test', markevery=2)
43 plt.xlabel("epochs")
C:\Users\Masaaki\Anaconda3\lib\site-packages\matplotlib\pyplot.py in plot(*args, **kwargs)
3316 mplDeprecation)
3317 try:
-> 3318 ret = ax.plot(*args, **kwargs)
3319 finally:
3320 ax._hold = washold
C:\Users\Masaaki\Anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, *args, **kwargs)
1889 warnings.warn(msg % (label_namer, func.__name__),
1890 RuntimeWarning, stacklevel=2)
-> 1891 return func(ax, *args, **kwargs)
1892 pre_doc = inner.__doc__
1893 if pre_doc is None:
C:\Users\Masaaki\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in plot(self, *args, **kwargs)
1404 kwargs = cbook.normalize_kwargs(kwargs, _alias_map)
1405
-> 1406 for line in self._get_lines(*args, **kwargs):
1407 self.add_line(line)
1408 lines.append(line)
C:\Users\Masaaki\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in _grab_next_args(self, *args, **kwargs)
405 return
406 if len(remaining) <= 3:
--> 407 for seg in self._plot_args(remaining, kwargs):
408 yield seg
409 return
C:\Users\Masaaki\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in _plot_args(self, tup, kwargs)
383 x, y = index_of(tup[-1])
384
--> 385 x, y = self._xy_from_xy(x, y)
386
387 if self.command == 'plot':
C:\Users\Masaaki\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in _xy_from_xy(self, x, y)
242 if x.shape[0] != y.shape[0]:
243 raise ValueError("x and y must have same first dimension, but "
--> 244 "have shapes {} and {}".format(x.shape, y.shape))
245 if x.ndim > 2 or y.ndim > 2:
246 raise ValueError("x and y can be no greater than 2-D, but have "
ValueError: x and y must have same first dimension, but have shapes (20,) and (5,)
In [ ]:
// straight_dataset_bmp.h
// 2017/07/24 by marsee
//
#ifndef __STRAIGHT_DATASET_BMP_H__
#define __STRAIGHT_DATASET_BMP_H__
#include "hls_video.h"
#define BMP_HEIGHT 600
#define BMP_WIDTH 800
#define REDUCTION_RATIO 0.075 // 1/13.3333... 60x45
#define DATASET_HEIGHT 10
#define DATASET_WIDTH 56
#define STRAIGHT_BMP_FILE_NAME straight
#define LEFT_TRUN_BMP_FILE_NAME left_turn
#define RIGHT_TRUN_BMP_FILE_NAME right_turn
#define STRAIGHT_NUM_OF_IMAGE 11
#define LEFT_TRUN_NUM_OF_IMAGE 11
#define RIGHT_TRUNNUM_OF_IMAGE 11
typedef hls::Scalar<3, unsigned char> RGB_PIXEL;
typedef hls::Mat<BMP_HEIGHT, BMP_WIDTH, HLS_8UC3> RGB_IMAGE;
typedef hls::Mat<BMP_HEIGHT, BMP_WIDTH, HLS_8UC1> GRAY_IMAGE;
#endif
// straight_dataset_bmp.cpp
// 2017/07/24 by marsee
//
#include <iostream>
#include "hls_opencv.h"
#include "straight_dataset_bmp.h"
#include <arpa/inet.h>
int main(){
char straight_fn[256] = "straight";
char left_turn_fn[256] = "left_turn";
char right_turn_fn[256] = "right_turn";
char bmp_file[256];
FILE *ftin, *ftln;
char train_image_name[256] = "train_straight_run_image";
char train_label_name[256] = "train_straight_run_label";
uint32_t buf[5];
uint8_t bufchar[100];
if ((ftin = fopen(train_image_name, "wb")) == NULL){
fprintf(stderr, "Can't open %s\n", train_image_name);
exit(1);
}
if ((ftln = fopen(train_label_name, "wb")) == NULL){
fprintf(stderr, "Can't open %s\n", train_label_name);
exit(1);
}
// Writed header
buf[0] = htonl(0x803); // magic number
buf[1] = htonl(5*5*(STRAIGHT_NUM_OF_IMAGE+LEFT_TRUN_NUM_OF_IMAGE+RIGHT_TRUNNUM_OF_IMAGE));
// number of image
buf[2] = htonl(10); // number of rows (10)
buf[3] = htonl(56); // number of columns (56)
fwrite(buf, sizeof(uint32_t), 4, ftin);
buf[0] = htonl(0x801); // magic number
buf[1] = htonl(5*5*(STRAIGHT_NUM_OF_IMAGE+LEFT_TRUN_NUM_OF_IMAGE+RIGHT_TRUNNUM_OF_IMAGE));
// number of image
fwrite(buf, sizeof(uint32_t), 2, ftln);
// refereed to http://opencv.jp/cookbook/opencv_img.html
// straight
for(int i=0; i<STRAIGHT_NUM_OF_IMAGE; i++){
sprintf(bmp_file, "%s%d.bmp", straight_fn, i);
cv::Mat straight_img = cv::imread(bmp_file,1);
if(straight_img.empty())
return(-1);
cv::Mat reduct_img(straight_img.rows*0.075, straight_img.cols*0.075, straight_img.type());
cv::resize(straight_img, reduct_img, reduct_img.size(), cv::INTER_LINEAR);
cv::Mat gray_img;
cv::cvtColor(reduct_img, gray_img, CV_BGR2GRAY);
sprintf(bmp_file, "%s_RED%d.bmp", straight_fn, i);
cv::imwrite(bmp_file, gray_img);
for(int y=0; y<5; y++){
for(int x=0; x<5; x++){
cv::Rect rect_center(x, 30+y, 56, 10);
cv::Mat img_rect(gray_img, rect_center);
sprintf(bmp_file, "%s_RED_rect%d_%d%d.bmp", straight_fn, i, y, x);
cv::imwrite(bmp_file, img_rect);
for(int iy=0; iy<img_rect.rows; iy++){
for(int ix=0; ix<img_rect.cols; ix++){
bufchar[ix] = img_rect.at<uchar>(iy, ix);
}
fwrite(bufchar, sizeof(uint8_t), img_rect.cols, ftin); // image write
}
bufchar[0] = 0x1;
fwrite(bufchar, sizeof(uint8_t), 1, ftln); // label write
}
}
}
// left turn
for(int i=0; i<LEFT_TRUN_NUM_OF_IMAGE; i++){
sprintf(bmp_file, "%s%d.bmp", left_turn_fn, i);
cv::Mat left_trun_img = cv::imread(bmp_file,1);
if(left_trun_img.empty())
return(-1);
cv::Mat reduct_img(left_trun_img.rows*0.075, left_trun_img.cols*0.075, left_trun_img.type());
cv::resize(left_trun_img, reduct_img, reduct_img.size(), cv::INTER_LINEAR);
cv::Mat gray_img;
cv::cvtColor(reduct_img, gray_img, CV_BGR2GRAY);
sprintf(bmp_file, "%s_RED%d.bmp", left_turn_fn, i);
cv::imwrite(bmp_file, gray_img);
for(int y=0; y<5; y++){
for(int x=0; x<5; x++){
cv::Rect rect_center(x, 30+y, 56, 10);
cv::Mat img_rect(gray_img, rect_center);
sprintf(bmp_file, "%s_RED_rect%d_%d%d.bmp", left_turn_fn, i, y, x);
cv::imwrite(bmp_file, img_rect);
for(int iy=0; iy<img_rect.rows; iy++){
for(int ix=0; ix<img_rect.cols; ix++){
bufchar[ix] = img_rect.at<uchar>(iy, ix);
}
fwrite(bufchar, sizeof(uint8_t), img_rect.cols, ftin); // image write
}
bufchar[0] = 0x0;
fwrite(bufchar, sizeof(uint8_t), 1, ftln); // label write
}
}
}
// right turn
for(int i=0; i<STRAIGHT_NUM_OF_IMAGE; i++){
sprintf(bmp_file, "%s%d.bmp", right_turn_fn, i);
cv::Mat right_trun_img = cv::imread(bmp_file,1);
if(right_trun_img.empty())
return(-1);
cv::Mat reduct_img(right_trun_img.rows*0.075, right_trun_img.cols*0.075, right_trun_img.type());
cv::resize(right_trun_img, reduct_img, reduct_img.size(), cv::INTER_LINEAR);
cv::Mat gray_img;
cv::cvtColor(reduct_img, gray_img, CV_BGR2GRAY);
sprintf(bmp_file, "%s_RED%d.bmp", right_turn_fn, i);
cv::imwrite(bmp_file, gray_img);
for(int y=0; y<5; y++){
for(int x=0; x<5; x++){
cv::Rect rect_center(x, 30+y, 56, 10);
cv::Mat img_rect(gray_img, rect_center);
sprintf(bmp_file, "%s_RED_rect%d_%d%d.bmp", right_turn_fn, i, y, x);
cv::imwrite(bmp_file, img_rect);
for(int iy=0; iy<img_rect.rows; iy++){
for(int ix=0; ix<img_rect.cols; ix++){
bufchar[ix] = img_rect.at<uchar>(iy, ix);
}
fwrite(bufchar, sizeof(uint8_t), img_rect.cols, ftin); // image write
}
bufchar[0] = 0x2;
fwrite(bufchar, sizeof(uint8_t), 1, ftln); // label write
}
}
}
fclose(ftin);
fclose(ftln);
return(0);
}
start_gui
source xsim.dir/tb_behav/xsim_script.tcl
# load_feature core
# current_fileset
INFO: [IP_Flow 19-234] Refreshing IP repositories
INFO: [IP_Flow 19-1704] No user IP repositories specified
INFO: [IP_Flow 19-2313] Loaded Vivado IP repository '/opt/Xilinx/Vivado/2017.2/data/ip'.
# xsim {tb_behav} -autoloadwcfg -tclbatch {tb.tcl} -key {Behavioral:sim_1:Functional:tb}
Vivado Simulator 2017.2
Time resolution is 1 ps
open_wave_config /home/masaaki/Vivado/zynq_base_ex_172/zynq_base_ex_172.sim/sim_1/behav/tb_behav.wcfg
source tb.tcl
## set curr_wave [current_wave_config]
## if { [string length $curr_wave] == 0 } {
## if { [llength [get_objects]] > 0} {
## add_wave /
## set_property needs_save false [current_wave_config]
## } else {
## send_msg_id Add_Wave-1 WARNING "No top level signals found. Simulator will start without a wave window. If you want to open a wave window go to 'File->New Waveform Configuration' or type 'create_wave_config' in the TCL console."
## }
## }
## run all
Block Memory Generator module tb.zynq_sys.base_zynq_i.blk_mem_gen_0.inst.native_mem_mapped_module.blk_mem_gen_v8_3_6_inst is using a behavioral model for simulation which will not precisely model memory collision behavior.
XilinxAXIVIP: Found at Path: tb.zynq_sys.base_zynq_i.processing_system7_0.inst.M_AXI_GP0.master
[0] : *ZYNQ_BFM_INFO : M_AXI_GP0 : Port is ENABLED.
XilinxAXIVIP: Found at Path: tb.zynq_sys.base_zynq_i.processing_system7_0.inst.M_AXI_GP1.master
[0] : *ZYNQ_BFM_INFO : M_AXI_GP1 : Port is DISABLED.
XilinxAXIVIP: Found at Path: tb.zynq_sys.base_zynq_i.processing_system7_0.inst.S_AXI_GP0.slave
[0] : *ZYNQ_BFM_INFO : S_AXI_GP0 : Port is DISABLED.
XilinxAXIVIP: Found at Path: tb.zynq_sys.base_zynq_i.processing_system7_0.inst.S_AXI_GP1.slave
[0] : *ZYNQ_BFM_INFO : S_AXI_GP1 : Port is DISABLED.
XilinxAXIVIP: Found at Path: tb.zynq_sys.base_zynq_i.processing_system7_0.inst.S_AXI_HP0.slave
[0] : *ZYNQ_BFM_INFO : S_AXI_HP0 : Port is DISABLED.
XilinxAXIVIP: Found at Path: tb.zynq_sys.base_zynq_i.processing_system7_0.inst.S_AXI_HP1.slave
[0] : *ZYNQ_BFM_INFO : S_AXI_HP1 : Port is DISABLED.
XilinxAXIVIP: Found at Path: tb.zynq_sys.base_zynq_i.processing_system7_0.inst.S_AXI_HP2.slave
[0] : *ZYNQ_BFM_INFO : S_AXI_HP2 : Port is DISABLED.
XilinxAXIVIP: Found at Path: tb.zynq_sys.base_zynq_i.processing_system7_0.inst.S_AXI_HP3.slave
[0] : *ZYNQ_BFM_INFO : S_AXI_HP3 : Port is DISABLED.
XilinxAXIVIP: Found at Path: tb.zynq_sys.base_zynq_i.processing_system7_0.inst.S_AXI_ACP.slave
[0] : *ZYNQ_BFM_INFO : S_AXI_ACP : Port is DISABLED.
running the tb
[150] : *ZYNQ_BFM_INFO : FPGA Soft Reset called for 0x1
[150] : *ZYNQ_BFM_INFO : FPGA Soft Reset called for 0x0
[150] : M_AXI_GP0 : *ZYNQ_BFM_INFO : Starting Address(0x41200000) -> AXI Write -> 4 bytes
[1490] : M_AXI_GP0 : *ZYNQ_BFM_INFO : Done AXI Write for Starting Address(0x41200000) with Response 'OKAY'
LEDs are toggled, observe the waveform
[1490] : M_AXI_GP0 : *ZYNQ_BFM_INFO : Starting Address(0x40000000) -> AXI Write -> 4 bytes
[1790] : M_AXI_GP0 : *ZYNQ_BFM_INFO : Done AXI Write for Starting Address(0x40000000) with Response 'OKAY'
[1790] : M_AXI_GP0 : *ZYNQ_BFM_INFO : Starting Address(0x40000000) -> AXI Read -> 4 bytes
[1950] : M_AXI_GP0 : *ZYNQ_BFM_INFO : Done AXI Read for Starting Address(0x40000000) with Response 'OKAY'
1950000, running the testbench, data read from BRAM was 32'hdeadbeef
AXI VIP Test PASSED
Simulation completed
masaaki@masaaki-VirtualBox2:~/Vivado/zynq_base_ex_172/zynq_base_ex_172.sim/sim_1/behav$ ./compile.sh
xvlog -m64 --relax -L smartconnect_v1_0 -L axi_protocol_checker_v1_1_14 -L xil_common_vip_v1_0_0 -L axi_vip_v1_0_2 -L axi_vip_v1_0_1 -prj tb_vlog.prj
INFO: [VRFC 10-2263] Analyzing Verilog file "/home/masaaki/Vivado/zynq_base_ex_172/zynq_base_ex_172.ip_user_files/bd/base_zynq/ip/base_zynq_processing_system7_0_0/sim/base_zynq_processing_system7_0_0.v" into library xil_defaultlib
INFO: [VRFC 10-311] analyzing module base_zynq_processing_system7_0_0
INFO: [VRFC 10-2263] Analyzing Verilog file "/home/masaaki/Vivado/zynq_base_ex_172/zynq_base_ex_172.ip_user_files/bd/base_zynq/ip/base_zynq_blk_mem_gen_0_0/sim/base_zynq_blk_mem_gen_0_0.v" into library xil_defaultlib
INFO: [VRFC 10-311] analyzing module base_zynq_blk_mem_gen_0_0
INFO: [VRFC 10-2263] Analyzing Verilog file "/home/masaaki/Vivado/zynq_base_ex_172/zynq_base_ex_172.ip_user_files/bd/base_zynq/ip/base_zynq_xbar_0/sim/base_zynq_xbar_0.v" into library xil_defaultlib
INFO: [VRFC 10-311] analyzing module base_zynq_xbar_0
INFO: [VRFC 10-2263] Analyzing Verilog file "/home/masaaki/Vivado/zynq_base_ex_172/zynq_base_ex_172.ip_user_files/bd/base_zynq/ip/base_zynq_auto_pc_0/sim/base_zynq_auto_pc_0.v" into library xil_defaultlib
INFO: [VRFC 10-311] analyzing module base_zynq_auto_pc_0
INFO: [VRFC 10-2263] Analyzing Verilog file "/home/masaaki/Vivado/zynq_base_ex_172/zynq_base_ex_172.ip_user_files/bd/base_zynq/ip/base_zynq_auto_pc_1/sim/base_zynq_auto_pc_1.v" into library xil_defaultlib
INFO: [VRFC 10-311] analyzing module base_zynq_auto_pc_1
INFO: [VRFC 10-2263] Analyzing SystemVerilog file "/home/masaaki/Vivado/zynq_base_ex_172/zynq_base_ex_172.srcs/sim_1/imports/base_zynq/zynq_tb.sv" into library xil_defaultlib
INFO: [VRFC 10-311] analyzing module tb
INFO: [VRFC 10-2263] Analyzing Verilog file "/home/masaaki/Vivado/zynq_base_ex_172/zynq_base_ex_172.sim/sim_1/behav/glbl.v" into library xil_defaultlib
INFO: [VRFC 10-311] analyzing module glbl
xvhdl -m64 --relax -prj tb_vhdl.prj
INFO: [VRFC 10-163] Analyzing VHDL file "/home/masaaki/Vivado/zynq_base_ex_172/zynq_base_ex_172.ip_user_files/bd/base_zynq/ip/base_zynq_axi_gpio_0_0/sim/base_zynq_axi_gpio_0_0.vhd" into library xil_defaultlib
INFO: [VRFC 10-307] analyzing entity base_zynq_axi_gpio_0_0
INFO: [VRFC 10-163] Analyzing VHDL file "/home/masaaki/Vivado/zynq_base_ex_172/zynq_base_ex_172.ip_user_files/bd/base_zynq/ip/base_zynq_axi_bram_ctrl_0_0/sim/base_zynq_axi_bram_ctrl_0_0.vhd" into library xil_defaultlib
INFO: [VRFC 10-307] analyzing entity base_zynq_axi_bram_ctrl_0_0
INFO: [VRFC 10-163] Analyzing VHDL file "/home/masaaki/Vivado/zynq_base_ex_172/zynq_base_ex_172.ip_user_files/bd/base_zynq/ip/base_zynq_rst_ps7_0_50M_0/sim/base_zynq_rst_ps7_0_50M_0.vhd" into library xil_defaultlib
INFO: [VRFC 10-307] analyzing entity base_zynq_rst_ps7_0_50M_0
INFO: [VRFC 10-163] Analyzing VHDL file "/home/masaaki/Vivado/zynq_base_ex_172/zynq_base_ex_172.ip_user_files/bd/base_zynq/hdl/base_zynq.vhd" into library xil_defaultlib
INFO: [VRFC 10-307] analyzing entity m00_couplers_imp_QHT96L
INFO: [VRFC 10-307] analyzing entity m01_couplers_imp_11WP2HX
INFO: [VRFC 10-307] analyzing entity s00_couplers_imp_1JB4A1T
INFO: [VRFC 10-307] analyzing entity base_zynq_ps7_0_axi_periph_0
INFO: [VRFC 10-307] analyzing entity base_zynq
INFO: [VRFC 10-163] Analyzing VHDL file "/home/masaaki/Vivado/zynq_base_ex_172/zynq_base_ex_172.srcs/sources_1/bd/base_zynq/hdl/base_zynq_wrapper.vhd" into library xil_defaultlib
INFO: [VRFC 10-307] analyzing entity base_zynq_wrapper
Running compilation flow
Done compilation
Done linking: "/home/masaaki/Vivado/zynq_base_ex_172/zynq_base_ex_172.sim/sim_1/behav/xsim.dir/xsc/dpi.so"
masaaki@masaaki-VirtualBox2:~/Vivado/zynq_base_ex_172/zynq_base_ex_172.sim/sim_1/behav$
masaaki@masaaki-VirtualBox2:~/Vivado/zynq_base_ex_172/zynq_base_ex_172.sim/sim_1/behav$ ./elaborate.sh
Vivado Simulator 2017.2
Copyright 1986-1999, 2001-2016 Xilinx, Inc. All Rights Reserved.
Running: /opt/Xilinx/Vivado/2017.2/bin/unwrapped/lnx64.o/xelab -wto 429c07435a554e888bf42dfaf10910cc --debug typical --relax --mt 8 -L axi_infrastructure_v1_1_0 -L xil_common_vip_v1_0_0 -L smartconnect_v1_0 -L axi_protocol_checker_v1_1_14 -L axi_vip_v1_0_2 -L axi_vip_v1_0_1 -L xil_defaultlib -L axi_lite_ipif_v3_0_4 -L lib_cdc_v1_0_2 -L interrupt_control_v3_1_4 -L axi_gpio_v2_0_15 -L blk_mem_gen_v8_3_6 -L axi_bram_ctrl_v4_0_11 -L proc_sys_reset_v5_0_11 -L generic_baseblocks_v2_1_0 -L axi_register_slice_v2_1_13 -L fifo_generator_v13_1_4 -L axi_data_fifo_v2_1_12 -L axi_crossbar_v2_1_14 -L axi_protocol_converter_v2_1_13 -L unisims_ver -L unimacro_ver -L secureip -L xpm --snapshot tb_behav xil_defaultlib.tb xil_defaultlib.glbl -log elaborate.log -cc gcc -sv_lib dpi
Using 8 slave threads.
Starting static elaboration
Starting simulation data flow analysis
Completed simulation data flow analysis
Time Resolution for simulation is 1ps
WARNING: [XSIM 43-3447] Restricting number of parallel compilation jobs to 4 to avoid system resource limitations.
Compiling package std.standard
Compiling package std.textio
Compiling package ieee.std_logic_1164
Compiling package unisim.vcomponents
Compiling package ieee.numeric_std
Compiling package ieee.std_logic_arith
Compiling package axi_bram_ctrl_v4_0_11.axi_bram_ctrl_funcs
Compiling package ieee.vital_timing
Compiling package ieee.vital_primitives
Compiling package unisim.vpkg
Compiling package ieee.std_logic_unsigned
Compiling package synopsys.attributes
Compiling package ieee.std_logic_misc
Compiling package axi_lite_ipif_v3_0_4.ipif_pkg
Compiling architecture implementation of entity axi_bram_ctrl_v4_0_11.sng_port_arb [\sng_port_arb(c_s_axi_addr_width...]
Compiling architecture implementation of entity axi_bram_ctrl_v4_0_11.wrap_brst [\wrap_brst(c_axi_addr_width=13,c...]
Compiling architecture muxcy_v of entity unisim.MUXCY [muxcy_default]
Compiling architecture muxcy_l_v of entity unisim.MUXCY_L [muxcy_l_default]
Compiling architecture xorcy_v of entity unisim.XORCY [xorcy_default]
Compiling architecture srl16e_v of entity unisim.SRL16E [\SRL16E(0,15)\]
Compiling architecture fdre_v of entity unisim.FDRE [fdre_default]
Compiling architecture fdr_v of entity unisim.FDR [fdr_default]
Compiling architecture imp of entity axi_bram_ctrl_v4_0_11.SRL_FIFO [\SRL_FIFO(c_data_bits=12,c_depth...]
Compiling architecture implementation of entity axi_bram_ctrl_v4_0_11.wr_chnl [\wr_chnl(c_axi_addr_width=13,c_a...]
Compiling architecture implementation of entity axi_bram_ctrl_v4_0_11.rd_chnl [\rd_chnl(c_axi_addr_width=13,c_a...]
Compiling architecture implementation of entity axi_bram_ctrl_v4_0_11.full_axi [\full_axi(c_s_axi_addr_width=13,...]
Compiling architecture implementation of entity axi_bram_ctrl_v4_0_11.axi_bram_ctrl_top [\axi_bram_ctrl_top(c_bram_addr_w...]
Compiling architecture implementation of entity axi_bram_ctrl_v4_0_11.axi_bram_ctrl [\axi_bram_ctrl(c_memory_depth=20...]
Compiling architecture base_zynq_axi_bram_ctrl_0_0_arch of entity xil_defaultlib.base_zynq_axi_bram_ctrl_0_0 [base_zynq_axi_bram_ctrl_0_0_defa...]
Compiling architecture imp of entity axi_lite_ipif_v3_0_4.pselect_f [\pselect_f(c_ab=2,c_aw=2,c_bar="...]
Compiling architecture imp of entity axi_lite_ipif_v3_0_4.pselect_f [\pselect_f(c_ab=2,c_aw=2,c_bar="...]
Compiling architecture imp of entity axi_lite_ipif_v3_0_4.pselect_f [\pselect_f(c_ab=2,c_aw=2,c_bar="...]
Compiling architecture imp of entity axi_lite_ipif_v3_0_4.pselect_f [\pselect_f(c_ab=2,c_aw=2,c_bar="...]
Compiling architecture imp of entity axi_lite_ipif_v3_0_4.address_decoder [\address_decoder(c_bus_awidth=9,...]
Compiling architecture imp of entity axi_lite_ipif_v3_0_4.slave_attachment [\slave_attachment(c_ard_addr_ran...]
Compiling architecture imp of entity axi_lite_ipif_v3_0_4.axi_lite_ipif [\axi_lite_ipif(c_s_axi_addr_widt...]
Compiling architecture implementation of entity lib_cdc_v1_0_2.cdc_sync [\cdc_sync(c_single_bit=0,c_vecto...]
Compiling architecture imp of entity axi_gpio_v2_0_15.GPIO_Core [\GPIO_Core(c_aw=9,c_gpio_width=4...]
Compiling architecture imp of entity axi_gpio_v2_0_15.axi_gpio [\axi_gpio(c_family="zynq",c_gpio...]
Compiling architecture base_zynq_axi_gpio_0_0_arch of entity xil_defaultlib.base_zynq_axi_gpio_0_0 [base_zynq_axi_gpio_0_0_default]
Compiling module blk_mem_gen_v8_3_6.blk_mem_gen_v8_3_6_output_stage(...
Compiling module blk_mem_gen_v8_3_6.blk_mem_gen_v8_3_6_output_stage(...
Compiling module blk_mem_gen_v8_3_6.blk_mem_gen_v8_3_6_softecc_outpu...
Compiling module blk_mem_gen_v8_3_6.blk_mem_gen_v8_3_6_mem_module(C_...
Compiling module blk_mem_gen_v8_3_6.blk_mem_gen_v8_3_6(C_FAMILY="zyn...
Compiling module xil_defaultlib.base_zynq_blk_mem_gen_0_0
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_ge...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_ge...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_ar...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_ar...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_fm...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_ar...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_ar...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_ar...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_ar...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_ss...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_in...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_sp...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_dd...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_oc...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_oc...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_re...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_re...
Compiling module axi_vip_v1_0_2.axi_vip_v1_0_2_if(C_AXI_PROTOCOL...
Compiling module smartconnect_v1_0.sc_util_v1_0_2_onehot_to_binary(...
Compiling module smartconnect_v1_0.sc_util_v1_0_2_srl_rtl(C_A_WIDTH...
Compiling module smartconnect_v1_0.sc_util_v1_0_2_axic_reg_srl_fifo...
Compiling module axi_protocol_checker_v1_1_14.axi_protocol_checker_v1_1_14_thr...
Compiling module axi_protocol_checker_v1_1_14.axi_protocol_checker_v1_1_14_syn...
Compiling module axi_protocol_checker_v1_1_14.axi_protocol_checker_v1_1_14_axi...
Compiling module axi_protocol_checker_v1_1_14.axi_protocol_checker_v1_1_14_syn...
Compiling module axi_protocol_checker_v1_1_14.axi_protocol_checker_v1_1_14_syn...
Compiling module axi_protocol_checker_v1_1_14.axi_protocol_checker_v1_1_14_cor...
Compiling module axi_protocol_checker_v1_1_14.axi_protocol_checker_v1_1_14_rep...
Compiling module axi_protocol_checker_v1_1_14.axi_protocol_checker_v1_1_14_top...
Compiling module axi_vip_v1_0_2.axi_vip_v1_0_2_top(C_AXI_PROTOCO...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_ax...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_ax...
Compiling module axi_vip_v1_0_2.axi_vip_v1_0_2_if(C_AXI_PROTOCOL...
Compiling module smartconnect_v1_0.sc_util_v1_0_2_onehot_to_binary(...
Compiling module smartconnect_v1_0.sc_util_v1_0_2_srl_rtl(C_A_WIDTH...
Compiling module smartconnect_v1_0.sc_util_v1_0_2_axic_reg_srl_fifo...
Compiling module axi_protocol_checker_v1_1_14.axi_protocol_checker_v1_1_14_thr...
Compiling module axi_protocol_checker_v1_1_14.axi_protocol_checker_v1_1_14_axi...
Compiling module axi_protocol_checker_v1_1_14.axi_protocol_checker_v1_1_14_syn...
Compiling module axi_protocol_checker_v1_1_14.axi_protocol_checker_v1_1_14_cor...
Compiling module axi_protocol_checker_v1_1_14.axi_protocol_checker_v1_1_14_rep...
Compiling module axi_protocol_checker_v1_1_14.axi_protocol_checker_v1_1_14_top...
Compiling module axi_vip_v1_0_2.axi_vip_v1_0_2_top(C_AXI_PROTOCO...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_ax...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_ax...
Compiling module axi_vip_v1_0_2.axi_vip_v1_0_2_if(C_AXI_PROTOCOL...
Compiling module axi_protocol_checker_v1_1_14.axi_protocol_checker_v1_1_14_axi...
Compiling module axi_protocol_checker_v1_1_14.axi_protocol_checker_v1_1_14_syn...
Compiling module axi_protocol_checker_v1_1_14.axi_protocol_checker_v1_1_14_cor...
Compiling module axi_protocol_checker_v1_1_14.axi_protocol_checker_v1_1_14_rep...
Compiling module axi_protocol_checker_v1_1_14.axi_protocol_checker_v1_1_14_top...
Compiling module axi_vip_v1_0_2.axi_vip_v1_0_2_top(C_AXI_PROTOCO...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_in...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_in...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_af...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_in...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_af...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_in...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_af...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_in...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_af...
Compiling module axi_vip_v1_0_2.axi_vip_v1_0_2_if(C_AXI_PROTOCOL...
Compiling module smartconnect_v1_0.sc_util_v1_0_2_onehot_to_binary(...
Compiling module smartconnect_v1_0.sc_util_v1_0_2_srl_rtl(C_A_WIDTH...
Compiling module smartconnect_v1_0.sc_util_v1_0_2_axic_reg_srl_fifo...
Compiling module axi_protocol_checker_v1_1_14.axi_protocol_checker_v1_1_14_thr...
Compiling module axi_protocol_checker_v1_1_14.axi_protocol_checker_v1_1_14_axi...
Compiling module axi_protocol_checker_v1_1_14.axi_protocol_checker_v1_1_14_cor...
Compiling module axi_protocol_checker_v1_1_14.axi_protocol_checker_v1_1_14_rep...
Compiling module axi_protocol_checker_v1_1_14.axi_protocol_checker_v1_1_14_top...
Compiling module axi_vip_v1_0_2.axi_vip_v1_0_2_top(C_AXI_PROTOCO...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1_ax...
Compiling module axi_vip_v1_0_1.processing_system7_vip_v1_0_1(C_...
Compiling module xil_defaultlib.base_zynq_processing_system7_0_0
Compiling module axi_infrastructure_v1_1_0.axi_infrastructure_v1_1_0_axi2ve...
Compiling module axi_register_slice_v2_1_13.axi_register_slice_v2_1_13_axic_...
Compiling module axi_register_slice_v2_1_13.axi_register_slice_v2_1_13_axic_...
Compiling module axi_register_slice_v2_1_13.axi_register_slice_v2_1_13_axic_...
Compiling module axi_register_slice_v2_1_13.axi_register_slice_v2_1_13_axic_...
Compiling module axi_infrastructure_v1_1_0.axi_infrastructure_v1_1_0_vector...
Compiling module axi_register_slice_v2_1_13.axi_register_slice_v2_1_13_axi_r...
Compiling module axi_protocol_converter_v2_1_13.axi_protocol_converter_v2_1_13_b...
Compiling module axi_protocol_converter_v2_1_13.axi_protocol_converter_v2_1_13_b...
Compiling module axi_protocol_converter_v2_1_13.axi_protocol_converter_v2_1_13_b...
Compiling module axi_protocol_converter_v2_1_13.axi_protocol_converter_v2_1_13_b...
Compiling module axi_protocol_converter_v2_1_13.axi_protocol_converter_v2_1_13_b...
Compiling module axi_protocol_converter_v2_1_13.axi_protocol_converter_v2_1_13_b...
Compiling module axi_protocol_converter_v2_1_13.axi_protocol_converter_v2_1_13_b...
Compiling module axi_protocol_converter_v2_1_13.axi_protocol_converter_v2_1_13_b...
Compiling module axi_protocol_converter_v2_1_13.axi_protocol_converter_v2_1_13_b...
Compiling module axi_protocol_converter_v2_1_13.axi_protocol_converter_v2_1_13_b...
Compiling module axi_protocol_converter_v2_1_13.axi_protocol_converter_v2_1_13_b...
Compiling module axi_protocol_converter_v2_1_13.axi_protocol_converter_v2_1_13_b...
Compiling module axi_protocol_converter_v2_1_13.axi_protocol_converter_v2_1_13_b...
Compiling module axi_infrastructure_v1_1_0.axi_infrastructure_v1_1_0_axi2ve...
Compiling module axi_register_slice_v2_1_13.axi_register_slice_v2_1_13_axic_...
Compiling module axi_register_slice_v2_1_13.axi_register_slice_v2_1_13_axic_...
Compiling module axi_register_slice_v2_1_13.axi_register_slice_v2_1_13_axic_...
Compiling module axi_register_slice_v2_1_13.axi_register_slice_v2_1_13_axic_...
Compiling module axi_infrastructure_v1_1_0.axi_infrastructure_v1_1_0_vector...
Compiling module axi_register_slice_v2_1_13.axi_register_slice_v2_1_13_axi_r...
Compiling module axi_protocol_converter_v2_1_13.axi_protocol_converter_v2_1_13_b...
Compiling module axi_protocol_converter_v2_1_13.axi_protocol_converter_v2_1_13_a...
Compiling module xil_defaultlib.base_zynq_auto_pc_0
Compiling architecture structure of entity xil_defaultlib.m00_couplers_imp_QHT96L [m00_couplers_imp_qht96l_default]
Compiling architecture structure of entity xil_defaultlib.m01_couplers_imp_11WP2HX [m01_couplers_imp_11wp2hx_default]
Compiling module axi_protocol_converter_v2_1_13.axi_protocol_converter_v2_1_13_a...
Compiling module xil_defaultlib.base_zynq_auto_pc_1
Compiling architecture structure of entity xil_defaultlib.s00_couplers_imp_1JB4A1T [s00_couplers_imp_1jb4a1t_default]
Compiling module generic_baseblocks_v2_1_0.generic_baseblocks_v2_1_0_carry_...
Compiling module generic_baseblocks_v2_1_0.generic_baseblocks_v2_1_0_compar...
Compiling module generic_baseblocks_v2_1_0.generic_baseblocks_v2_1_0_compar...
Compiling module axi_crossbar_v2_1_14.axi_crossbar_v2_1_14_addr_decode...
Compiling module generic_baseblocks_v2_1_0.generic_baseblocks_v2_1_0_mux_en...
Compiling module unisims_ver.SRLC32E_default_1
Compiling module axi_data_fifo_v2_1_12.axi_data_fifo_v2_1_12_ndeep_srl(...
Compiling module axi_data_fifo_v2_1_12.axi_data_fifo_v2_1_12_axic_srl_f...
Compiling module axi_crossbar_v2_1_14.axi_crossbar_v2_1_14_si_transact...
Compiling module generic_baseblocks_v2_1_0.generic_baseblocks_v2_1_0_mux_en...
Compiling module axi_crossbar_v2_1_14.axi_crossbar_v2_1_14_si_transact...
Compiling module axi_crossbar_v2_1_14.axi_crossbar_v2_1_14_splitter
Compiling module unisims_ver.SRLC32E_default
Compiling module axi_data_fifo_v2_1_12.axi_data_fifo_v2_1_12_ndeep_srl(...
Compiling module axi_data_fifo_v2_1_12.axi_data_fifo_v2_1_12_axic_reg_s...
Compiling module axi_crossbar_v2_1_14.axi_crossbar_v2_1_14_wdata_route...
Compiling module axi_crossbar_v2_1_14.axi_crossbar_v2_1_14_wdata_mux(C...
Compiling module axi_data_fifo_v2_1_12.axi_data_fifo_v2_1_12_axic_srl_f...
Compiling module axi_infrastructure_v1_1_0.axi_infrastructure_v1_1_0_axi2ve...
Compiling module axi_register_slice_v2_1_13.axi_register_slice_v2_1_13_axic_...
Compiling module axi_register_slice_v2_1_13.axi_register_slice_v2_1_13_axic_...
Compiling module axi_register_slice_v2_1_13.axi_register_slice_v2_1_13_axic_...
Compiling module axi_register_slice_v2_1_13.axi_register_slice_v2_1_13_axic_...
Compiling module axi_infrastructure_v1_1_0.axi_infrastructure_v1_1_0_vector...
Compiling module axi_register_slice_v2_1_13.axi_register_slice_v2_1_13_axi_r...
Compiling module axi_crossbar_v2_1_14.axi_crossbar_v2_1_14_wdata_mux(C...
Compiling module axi_data_fifo_v2_1_12.axi_data_fifo_v2_1_12_ndeep_srl(...
Compiling module axi_data_fifo_v2_1_12.axi_data_fifo_v2_1_12_axic_srl_f...
Compiling module axi_crossbar_v2_1_14.axi_crossbar_v2_1_14_addr_arbite...
Compiling module axi_crossbar_v2_1_14.axi_crossbar_v2_1_14_decerr_slav...
Compiling module axi_crossbar_v2_1_14.axi_crossbar_v2_1_14_crossbar(C_...
Compiling module axi_crossbar_v2_1_14.axi_crossbar_v2_1_14_axi_crossba...
Compiling module xil_defaultlib.base_zynq_xbar_0
Compiling architecture structure of entity xil_defaultlib.base_zynq_ps7_0_axi_periph_0 [base_zynq_ps7_0_axi_periph_0_def...]
Compiling architecture implementation of entity lib_cdc_v1_0_2.cdc_sync [\cdc_sync(c_vector_width=2,c_mtb...]
Compiling architecture srl16e_v of entity unisim.SRL16E [\SRL16E(init="1111111111111111")...]
Compiling architecture srl16_v of entity unisim.SRL16 [\SRL16(init="1111111111111111")(...]
Compiling architecture imp of entity proc_sys_reset_v5_0_11.lpf [\lpf(c_ext_rst_width=4,c_aux_rst...]
Compiling architecture imp of entity proc_sys_reset_v5_0_11.upcnt_n [\upcnt_n(c_size=6)\]
Compiling architecture imp of entity proc_sys_reset_v5_0_11.sequence_psr [sequence_psr_default]
Compiling architecture imp of entity proc_sys_reset_v5_0_11.proc_sys_reset [\proc_sys_reset(c_family="zynq",...]
Compiling architecture base_zynq_rst_ps7_0_50m_0_arch of entity xil_defaultlib.base_zynq_rst_ps7_0_50M_0 [base_zynq_rst_ps7_0_50m_0_defaul...]
Compiling architecture structure of entity xil_defaultlib.base_zynq [base_zynq_default]
Compiling architecture structure of entity xil_defaultlib.base_zynq_wrapper [base_zynq_wrapper_default]
Compiling module xil_defaultlib.tb
Compiling module xil_defaultlib.glbl
Compiling package axi_vip_v1_0_2.axi_vip_v1_0_2_pkg
Compiling package xil_common_vip_v1_0_0.xil_common_vip_v1_0_0_pkg
Compiling package std.std
Compiling package smartconnect_v1_0.sc_util_v1_0_2_pkg
Waiting for 4 sub-compilation(s) to finish...
0 sub-compilation(s) remaining...
Built simulation snapshot tb_behav
masaaki@masaaki-VirtualBox2:~/Vivado/zynq_base_ex_172/zynq_base_ex_172.sim/sim_1/behav$
// zynq_dpi.c
// 2017/08/12 by marsee
//
#include "svdpi.h"
#define AXI_TRANS_CS_LIMIT 10
#define READ_STATE 1
const struct axi_trans_scenario {
int r_w;
int delay;
int addr;
int trans_bytes;
int data;
} axi_trans_sc[AXI_TRANS_CS_LIMIT] =
{{0, 0, 0x41200000, 4, 0xFFFFFFFF},
{0, 0, 0x40000000, 4, 0xDEADBEEF},
{1, 0, 0x40000000, 4, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}};
static int i=0;
int write_axit(int * const delay, int * const addr,
int * const trans_bytes, int * const data){
int r_w;
r_w = axi_trans_sc[i].r_w;
*delay = axi_trans_sc[i].delay;
*addr = axi_trans_sc[i].addr;
*trans_bytes = axi_trans_sc[i].trans_bytes;
*data = axi_trans_sc[i].data;
if(axi_trans_sc[i].trans_bytes != 0 && i<AXI_TRANS_CS_LIMIT){
if(r_w == 0){
i++;
return(0);
}else
return(1);
}else
return(2);
}
int read_axit(int * const delay, int * const addr,
int * const trans_bytes){
int r_w;
r_w = axi_trans_sc[i].r_w;
*delay = axi_trans_sc[i].delay;
*addr = axi_trans_sc[i].addr;
*trans_bytes = axi_trans_sc[i].trans_bytes;
if(axi_trans_sc[i].trans_bytes != 0 && i<AXI_TRANS_CS_LIMIT){
if(r_w == 1){
i++;
return(0);
}else
return(1);
}else
return(2);
}
integer delay, trans_bytes, addr;
integer data;
integer i;
import "DPI-C" function int write_axit(
output int delay,
output int addr,
output int trans_bytes,
output int data);
import "DPI-C" function int read_axit(
output int delay,
output int addr,
output int trans_bytes);
//This drives the LEDs on the GPIO output
if(write_axit(delay, addr, trans_bytes, data) == 0) begin
for(i=0; i<delay; i++) begin
#1;
end
tb.zynq_sys.base_zynq_i.processing_system7_0.inst.write_data(addr,trans_bytes, data, resp);
end
$display ("LEDs are toggled, observe the waveform");
//Write into the BRAM through GP0 and read back
if(write_axit(delay, addr, trans_bytes, data) == 0) begin
for(i=0; i<delay; i++) begin
#1;
end
tb.zynq_sys.base_zynq_i.processing_system7_0.inst.write_data(addr,trans_bytes, data, resp);
end
if(read_axit(delay, addr, trans_bytes) == 0) begin
for(i=0; i<delay; i++) begin
#1;
end
tb.zynq_sys.base_zynq_i.processing_system7_0.inst.read_data(addr, trans_bytes, read_data, resp);
end
Steps
-----
1. Run the setup for Xilinx executables.
2. Check if the executables "xsc" and "xelab" are in your PATH.
3. Invoke run.csh
This example shows a simple DPI-C export usage. The System Verilog code (file.sv)
calls a function "cFunc" defined in function.c that in turn calls a function "svFunc" which is
defined on the SV side in the file file.sv.
1. First the xvlog/xelab combination is run to generate the header dpi.h that is included
in the function.c
2. Then the C code is compiled using xsc to create a dll in directory xsim.dir/xsc/dpi.so.
3. This dll is then linked into when using "xelab" to compile the file.sv
The return value is checked by the System Verilog code triggering a "PASSED" output for a valid run.
#include "dpi.h"
int cFunc(int x)
{
return svFunc(x) ;
}
// XSIP watermark, do not delete 67d7842dbbe25473c3c32b93c0da8047785f30d78e8a024de1b57352245f9689
module TOP();
export "DPI-C" function svFunc ;
int svValue ;
function int svFunc(input int x) ;
svValue = x + 1 ;
return svValue + 3 ;
endfunction
import "DPI-C" function int cFunc(input int x) ;
int result ;
initial
begin
svValue = 15 ;
result = cFunc(3) ;
if (svValue != 4)
begin
$display("FAILED") ;
$finish ;
end
if (result == 7)
$display("PASSED") ;
else
$display("FAILED") ;
end
endmodule
#!/bin/csh -xvf
xvlog -sv file.sv
xelab TOP -dpiheader dpi.h
xsc function.c
xelab TOP -sv_lib dpi -R
Steps
-----
1. Run the setup for Xilinx executables.
2. Check if the executables "xsc" and "xelab" are in your PATH.
3. Invoke run.csh
This example shows a simple DPI-C import usage. The System Verilog code (file.sv)
calls a function "myFunction" that is defined on the C side in the file function.c.
The C code is compiled using xsc to create a dll in directory xsim.dir/xsc/dpi.so.
This dll is then linked into when using "xelab" to compile the file.sv
You could use your own compiler (gcc) for compiling and creating a dll.
myFunction() call into the C code returns an C integer value of 5 which is then checked
by the System Verilog code triggering a "PASSED" output for a valid run.
#include "svdpi.h"
DPI_DLLESPEC
int myFunction()
{
return 5;
}
// XSIP watermark, do not delete 67d7842dbbe25473c3c32b93c0da8047785f30d78e8a024de1b57352245f9689
module m();
import "DPI-C" pure function int myFunction ();
int i;
initial
begin
#1;
i = myFunction();
if( i == 5)
$display("PASSED");
else
$display("FAILED");
$finish();
end
endmodule
#!/bin/csh -xvf
xsc function.c
xvlog -svlog file.sv
xelab work.m -sv_lib dpi -R
xsc コ ンパイ ラ を使用する と、 1 つまたは複数の C フ ァ イルから共有ラ イブラ リ (Windows の場合は .a、 Linux の場合は .so) を作成でき ます。
input_size_y = input_dim[1]
input_size_x = input_dim[2]
conv_output_size_y = (input_size_y - filter_size + 2*filter_pad) / filter_stride + 1
conv_output_size_x = (input_size_x - filter_size + 2*filter_pad) / filter_stride + 1
pool_output_size = int(filter_num * (conv_output_size_y/2) * (conv_output_size_x/2))
# simple_convnet.py
# 2017/08/08 白線追従走行用CNNに変更 by marsee
# 元になったコードは、https://github.com/oreilly-japan/deep-learning-from-scratch にあります。
# 改変したコードもMITライセンスとします。 2017/08/08 by marsee
# coding: utf-8
import sys, os
sys.path.append(os.pardir) # 親ディレクトリのファイルをインポートするための設定
import pickle
import numpy as np
from collections import OrderedDict
from common.layers import *
from common.gradient import numerical_gradient
class SimpleConvNet:
"""単純なConvNet
conv - relu - pool - affine - relu - affine - softmax
Parameters
----------
input_size : 入力サイズ(MNISTの場合は784)
hidden_size_list : 隠れ層のニューロンの数のリスト(e.g. [100, 100, 100])
output_size : 出力サイズ(MNISTの場合は10)
activation : 'relu' or 'sigmoid'
weight_init_std : 重みの標準偏差を指定(e.g. 0.01)
'relu'または'he'を指定した場合は「Heの初期値」を設定
'sigmoid'または'xavier'を指定した場合は「Xavierの初期値」を設定
"""
def __init__(self, input_dim=(1, 10, 56),
conv_param={'filter_num':30, 'filter_size':5, 'pad':0, 'stride':1},
hidden_size=100, output_size=10, weight_init_std=0.01):
filter_num = conv_param['filter_num']
filter_size = conv_param['filter_size']
filter_pad = conv_param['pad']
filter_stride = conv_param['stride']
input_size_y = input_dim[1]
input_size_x = input_dim[2]
conv_output_size_y = (input_size_y - filter_size + 2*filter_pad) / filter_stride + 1
conv_output_size_x = (input_size_x - filter_size + 2*filter_pad) / filter_stride + 1
pool_output_size = int(filter_num * (conv_output_size_y/2) * (conv_output_size_x/2))
print("pool_output_size ={0}".format(pool_output_size))
# 重みの初期化
self.params = {}
self.params['W1'] = weight_init_std * \
np.random.randn(filter_num, input_dim[0], filter_size, filter_size)
self.params['b1'] = np.zeros(filter_num)
self.params['W2'] = weight_init_std * \
np.random.randn(pool_output_size, hidden_size)
self.params['b2'] = np.zeros(hidden_size)
self.params['W3'] = weight_init_std * \
np.random.randn(hidden_size, output_size)
self.params['b3'] = np.zeros(output_size)
# レイヤの生成
self.layers = OrderedDict()
self.layers['Conv1'] = Convolution(self.params['W1'], self.params['b1'],
conv_param['stride'], conv_param['pad'])
self.layers['Relu1'] = Relu()
self.layers['Pool1'] = Pooling(pool_h=2, pool_w=2, stride=2)
self.layers['Affine1'] = Affine(self.params['W2'], self.params['b2'])
self.layers['Relu2'] = Relu()
self.layers['Affine2'] = Affine(self.params['W3'], self.params['b3'])
self.last_layer = SoftmaxWithLoss()
def predict(self, x):
for layer in self.layers.values():
x = layer.forward(x)
return x
def loss(self, x, t):
"""損失関数を求める
引数のxは入力データ、tは教師ラベル
"""
y = self.predict(x)
return self.last_layer.forward(y, t)
def accuracy(self, x, t, batch_size=100):
if t.ndim != 1 : t = np.argmax(t, axis=1)
acc = 0.0
for i in range(int(x.shape[0] / batch_size)):
tx = x[i*batch_size:(i+1)*batch_size]
tt = t[i*batch_size:(i+1)*batch_size]
y = self.predict(tx)
y = np.argmax(y, axis=1)
acc += np.sum(y == tt)
return acc / x.shape[0]
def numerical_gradient(self, x, t):
"""勾配を求める(数値微分)
Parameters
----------
x : 入力データ
t : 教師ラベル
Returns
-------
各層の勾配を持ったディクショナリ変数
grads['W1']、grads['W2']、...は各層の重み
grads['b1']、grads['b2']、...は各層のバイアス
"""
loss_w = lambda w: self.loss(x, t)
grads = {}
for idx in (1, 2, 3):
grads['W' + str(idx)] = numerical_gradient(loss_w, self.params['W' + str(idx)])
grads['b' + str(idx)] = numerical_gradient(loss_w, self.params['b' + str(idx)])
return grads
def gradient(self, x, t):
"""勾配を求める(誤差逆伝搬法)
Parameters
----------
x : 入力データ
t : 教師ラベル
Returns
-------
各層の勾配を持ったディクショナリ変数
grads['W1']、grads['W2']、...は各層の重み
grads['b1']、grads['b2']、...は各層のバイアス
"""
# forward
self.loss(x, t)
# backward
dout = 1
dout = self.last_layer.backward(dout)
layers = list(self.layers.values())
layers.reverse()
for layer in layers:
dout = layer.backward(dout)
# 設定
grads = {}
grads['W1'], grads['b1'] = self.layers['Conv1'].dW, self.layers['Conv1'].db
grads['W2'], grads['b2'] = self.layers['Affine1'].dW, self.layers['Affine1'].db
grads['W3'], grads['b3'] = self.layers['Affine2'].dW, self.layers['Affine2'].db
return grads
def save_params(self, file_name="params.pkl"):
params = {}
for key, val in self.params.items():
params[key] = val
with open(file_name, 'wb') as f:
pickle.dump(params, f)
def load_params(self, file_name="params.pkl"):
with open(file_name, 'rb') as f:
params = pickle.load(f)
for key, val in params.items():
self.params[key] = val
for i, key in enumerate(['Conv1', 'Affine1', 'Affine2']):
self.layers[key].W = self.params['W' + str(i+1)]
self.layers[key].b = self.params['b' + str(i+1)]
# train_convnet.py
# 2017/08/08 白線追従走行用CNNに変更 by marsee
# 元になったコードは、https://github.com/oreilly-japan/deep-learning-from-scratch にあります。
# 改変したコードもMITライセンスとします。 2017/08/08 by marsee
# coding: utf-8
import sys, os
sys.path.append(os.pardir) # 親ディレクトリのファイルをインポートするための設定
import numpy as np
import matplotlib.pyplot as plt
from dataset_straight.straight_dataset import load_mnist
from simple_convnet import SimpleConvNet
from common.trainer import Trainer
# データの読み込み
(x_train, t_train), (x_test, t_test) = load_mnist(flatten=False)
# 処理に時間のかかる場合はデータを削減
#x_train, t_train = x_train[:5000], t_train[:5000]
#x_test, t_test = x_test[:1000], t_test[:1000]
max_epochs = 20
network = SimpleConvNet(input_dim=(1,10,56),
conv_param = {'filter_num': 30, 'filter_size': 5, 'pad': 0, 'stride': 1},
hidden_size=100, output_size=3, weight_init_std=0.01)
trainer = Trainer(network, x_train, t_train, x_test, t_test,
epochs=max_epochs, mini_batch_size=100,
optimizer='Adam', optimizer_param={'lr': 0.001},
evaluate_sample_num_per_epoch=100)
trainer.train()
# パラメータの保存
network.save_params("params.pkl")
print("Saved Network Parameters!")
# グラフの描画
markers = {'train': 'o', 'test': 's'}
x = np.arange(max_epochs)
plt.plot(x, trainer.train_acc_list, marker='o', label='train', markevery=2)
plt.plot(x, trainer.test_acc_list, marker='s', label='test', markevery=2)
plt.xlabel("epochs")
plt.ylabel("accuracy")
plt.ylim(0, 1.0)
plt.legend(loc='lower right')
plt.show()
pool_output_size =2340
train loss:1.09740103666
=== epoch:1, train acc:0.0, test acc:0.0 ===
train loss:1.09619339353
train loss:1.09805550027
train loss:1.09687513729
train loss:1.0943589982
train loss:1.09043641309
train loss:1.08765370932
train loss:1.08988835762
train loss:1.08589893222
train loss:1.08082757519
train loss:1.07091805021
train loss:1.06677488283
train loss:1.07590794106
train loss:1.07036316486
train loss:1.0564093902
train loss:1.04913884878
=== epoch:2, train acc:1.0, test acc:1.0 ===
train loss:1.05282141475
train loss:1.02463171511
train loss:1.03238803274
train loss:1.01808300652
train loss:1.00418097479
train loss:0.994927691467
train loss:0.971943720127
train loss:0.938959564805
train loss:0.959999566898
train loss:0.964902849483
train loss:0.930027599907
train loss:0.910958350671
train loss:0.912115741252
train loss:0.877372771453
train loss:0.881933637438
=== epoch:3, train acc:1.0, test acc:1.0 ===
train loss:0.82203361721
train loss:0.875176827014
train loss:0.799964071175
train loss:0.801881639351
train loss:0.815978625085
train loss:0.779677387859
train loss:0.808213315743
train loss:0.779122522377
train loss:0.67732259731
train loss:0.664630569144
train loss:0.696595385714
train loss:0.804241795734
train loss:0.665426441902
train loss:0.672940861823
train loss:0.65431805427
=== epoch:4, train acc:1.0, test acc:1.0 ===
train loss:0.733642727716
train loss:0.724044016753
train loss:0.728747015891
train loss:0.645574644162
train loss:0.563772565951
train loss:0.650969893624
train loss:0.71471792151
train loss:0.562708504548
train loss:0.603808048409
train loss:0.599713674484
train loss:0.627750549668
train loss:0.554349357064
train loss:0.615028866599
train loss:0.581826815111
train loss:0.614025507529
=== epoch:5, train acc:0.98, test acc:0.98 ===
train loss:0.536548177427
train loss:0.616438072707
train loss:0.545175491413
train loss:0.59173160996
train loss:0.593612159015
train loss:0.599846111758
train loss:0.602536956687
train loss:0.526653021569
train loss:0.493542164942
train loss:0.652987814042
train loss:0.593193099959
train loss:0.651098995425
train loss:0.583797795175
train loss:0.497425254547
train loss:0.50022478405
=== epoch:6, train acc:1.0, test acc:0.99 ===
train loss:0.546986740154
train loss:0.632857452048
train loss:0.596720193602
train loss:0.628242539831
train loss:0.516102642255
train loss:0.584049938495
train loss:0.643520590658
train loss:0.433788079879
train loss:0.464739965862
train loss:0.517770447956
train loss:0.565927389082
train loss:0.574423786278
train loss:0.487440270503
train loss:0.460763808238
train loss:0.50437176485
=== epoch:7, train acc:0.91, test acc:0.8 ===
train loss:0.539680492517
train loss:0.43184783555
train loss:0.463142994517
train loss:0.40834945717
train loss:0.502730258745
train loss:0.530335381027
train loss:0.483509730618
train loss:0.419754214749
train loss:0.542743643599
train loss:0.545018581985
train loss:0.527738479101
train loss:0.552609220918
train loss:0.511188282627
train loss:0.439410114208
train loss:0.547204230479
=== epoch:8, train acc:0.87, test acc:0.74 ===
train loss:0.42177291798
train loss:0.37878361722
train loss:0.553163684557
train loss:0.573063758222
train loss:0.39186244896
train loss:0.445078706415
train loss:0.462594294123
train loss:0.438555772242
train loss:0.385638041553
train loss:0.415701287503
train loss:0.391015150038
train loss:0.468615281475
train loss:0.504983134551
train loss:0.377033870421
train loss:0.39501268333
=== epoch:9, train acc:0.95, test acc:0.89 ===
train loss:0.387747127634
train loss:0.385348791912
train loss:0.482271444765
train loss:0.397431981912
train loss:0.38837660175
train loss:0.456368766821
train loss:0.381980621014
train loss:0.320979196606
train loss:0.374925172354
train loss:0.424100142739
train loss:0.339776275437
train loss:0.379021958425
train loss:0.415783734932
train loss:0.312515924983
train loss:0.493949450648
=== epoch:10, train acc:0.99, test acc:0.9 ===
train loss:0.443524574076
train loss:0.357979512064
train loss:0.415673465881
train loss:0.362790259715
train loss:0.25231192493
train loss:0.405671943517
train loss:0.35069212333
train loss:0.372544883284
train loss:0.409110864872
train loss:0.343560294381
train loss:0.31804787133
train loss:0.403356537286
train loss:0.268652788357
train loss:0.394903753068
=============== Final Test Accuracy ===============
test acc:0.714666666667
Saved Network Parameters!
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-3-d6e09c53f736> in <module>()
36 markers = {'train': 'o', 'test': 's'}
37 x = np.arange(max_epochs)
---> 38 plt.plot(x, trainer.train_acc_list, marker='o', label='train', markevery=2)
39 plt.plot(x, trainer.test_acc_list, marker='s', label='test', markevery=2)
40 plt.xlabel("epochs")
C:\Users\Masaaki\Anaconda3\lib\site-packages\matplotlib\pyplot.py in plot(*args, **kwargs)
3316 mplDeprecation)
3317 try:
-> 3318 ret = ax.plot(*args, **kwargs)
3319 finally:
3320 ax._hold = washold
C:\Users\Masaaki\Anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, *args, **kwargs)
1889 warnings.warn(msg % (label_namer, func.__name__),
1890 RuntimeWarning, stacklevel=2)
-> 1891 return func(ax, *args, **kwargs)
1892 pre_doc = inner.__doc__
1893 if pre_doc is None:
C:\Users\Masaaki\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in plot(self, *args, **kwargs)
1404 kwargs = cbook.normalize_kwargs(kwargs, _alias_map)
1405
-> 1406 for line in self._get_lines(*args, **kwargs):
1407 self.add_line(line)
1408 lines.append(line)
C:\Users\Masaaki\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in _grab_next_args(self, *args, **kwargs)
405 return
406 if len(remaining) <= 3:
--> 407 for seg in self._plot_args(remaining, kwargs):
408 yield seg
409 return
C:\Users\Masaaki\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in _plot_args(self, tup, kwargs)
383 x, y = index_of(tup[-1])
384
--> 385 x, y = self._xy_from_xy(x, y)
386
387 if self.command == 'plot':
C:\Users\Masaaki\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in _xy_from_xy(self, x, y)
242 if x.shape[0] != y.shape[0]:
243 raise ValueError("x and y must have same first dimension, but "
--> 244 "have shapes {} and {}".format(x.shape, y.shape))
245 if x.ndim > 2 or y.ndim > 2:
246 raise ValueError("x and y can be no greater than 2-D, but have "
ValueError: x and y must have same first dimension, but have shapes (20,) and (10,)
In [21]:
print(network.params['W1'].shape)
# straight_dataset.py
# 2017/08/08 白線追従走行用CNNに変更 by marsee
# 元になったコードは、https://github.com/oreilly-japan/deep-learning-from-scratch の mnist.py です
# 改変したコードもMITライセンスとします。 2017/08/08 by marsee
# coding: utf-8
try:
import urllib.request
except ImportError:
raise ImportError('You should use Python 3.x')
import os.path
import gzip
import pickle
import os
import numpy as np
key_file = {
'train_img':'train_straight_run_image',
'train_label':'train_straight_run_label',
'test_img':'test_straight_run_image',
'test_label':'test_straight_run_label'
}
dataset_dir = os.path.dirname(os.path.abspath(__file__))
save_file = dataset_dir + "/mnist.pkl"
train_num = 750
test_num = 375
img_dim = (1, 10, 56)
img_size = 560
def _load_label(file_name):
file_path = dataset_dir + "/" + file_name
print("Converting " + file_name + " to NumPy Array ...")
with open(file_path, 'rb') as f:
labels = np.frombuffer(f.read(), np.uint8, offset=8)
print("Done")
return labels
def _load_img(file_name):
file_path = dataset_dir + "/" + file_name
print("Converting " + file_name + " to NumPy Array ...")
with open(file_path, 'rb') as f:
data = np.frombuffer(f.read(), np.uint8, offset=16)
data = data.reshape(-1, img_size)
print("Done")
return data
def _convert_numpy():
dataset = {}
dataset['train_img'] = _load_img(key_file['train_img'])
dataset['train_label'] = _load_label(key_file['train_label'])
dataset['test_img'] = _load_img(key_file['test_img'])
dataset['test_label'] = _load_label(key_file['test_label'])
return dataset
def init_mnist():
dataset = _convert_numpy()
print("Creating pickle file ...")
with open(save_file, 'wb') as f:
pickle.dump(dataset, f, -1)
print("Done!")
def _change_one_hot_label(X):
T = np.zeros((X.size, 3))
for idx, row in enumerate(T):
row[X[idx]] = 1
return T
def load_mnist(normalize=True, flatten=True, one_hot_label=False):
"""MNISTデータセットの読み込み
Parameters
----------
normalize : 画像のピクセル値を0.0~1.0に正規化する
one_hot_label :
one_hot_labelがTrueの場合、ラベルはone-hot配列として返す
one-hot配列とは、たとえば[0,0,1,0,0,0,0,0,0,0]のような配列
flatten : 画像を一次元配列に平にするかどうか
Returns
-------
(訓練画像, 訓練ラベル), (テスト画像, テストラベル)
"""
if not os.path.exists(save_file):
init_mnist()
with open(save_file, 'rb') as f:
dataset = pickle.load(f)
if normalize:
for key in ('train_img', 'test_img'):
dataset[key] = dataset[key].astype(np.float32)
dataset[key] /= 255.0
if one_hot_label:
dataset['train_label'] = _change_one_hot_label(dataset['train_label'])
dataset['test_label'] = _change_one_hot_label(dataset['test_label'])
if not flatten:
for key in ('train_img', 'test_img'):
dataset[key] = dataset[key].reshape(-1, 1, 10, 56)
return (dataset['train_img'], dataset['train_label']), (dataset['test_img'], dataset['test_label'])
if __name__ == '__main__':
init_mnist()
白線追従テストデータ測定方法
<直進>
ミニロボットカーが真っ直ぐの時の角度 111度
左、右 ±7度
左右車輪が白線の真ん中、姿勢は真っ直ぐ
<左ターン>
白線内 +15度
白線内 +20度
右車輪白線逸脱車体1/4
右車輪白線逸脱車体1/4 + +10度
右車輪白線逸脱車体1/2
<右ターン>
白線内 -15度
白線内 -20度
左車輪白線逸脱車体1/4
左車輪白線逸脱車体1/4 + -10度
左車輪白線逸脱車体1/2
// straight_dataset_check.cpp
// 2017/08/02 by marsee
//
#include <iostream>
#include "hls_opencv.h"
#include "straight_dataset_bmp.h"
#define IMAGE_NUMBER 4
int main(){
FILE *ftin, *ftln;
char train_image_name[256] = "train_straight_run_image";
uint8_t buf[600];
if ((ftin = fopen(train_image_name, "rb")) == NULL){
fprintf(stderr, "Can't open %s\n", train_image_name);
exit(1);
}
fread(buf, sizeof(uint32_t), 4, ftin); // header read
for(int i=0; i<=IMAGE_NUMBER; i++){
fread(buf, sizeof(uint8_t), DATASET_HEIGHT*DATASET_WIDTH, ftin);
}
cv::Mat wlt_img(cv::Size(56, 10), CV_8UC1);
for (int y = 0; y < wlt_img.rows; y++) {
for (int x = 0; x < wlt_img.cols; x++) {
wlt_img.at<uchar>(y, x) = buf[y*DATASET_WIDTH+x];
}
}
cv::imwrite("output.bmp", wlt_img);
fclose(ftin);
return(0);
}
// straight_dataset_bmp.cpp
// 2017/07/24 by marsee
//
#include <iostream>
#include "hls_opencv.h"
#include "straight_dataset_bmp.h"
#include <arpa/inet.h>
int main(){
char straight_fn[256] = "straight";
char left_turn_fn[256] = "left_turn";
char right_turn_fn[256] = "right_turn";
char bmp_file[256];
FILE *ftin, *ftln;
char train_image_name[256] = "train_straight_run_image";
char train_label_name[256] = "train_straight_run_label";
uint32_t buf[5];
uint8_t bufchar[100];
if ((ftin = fopen(train_image_name, "wb")) == NULL){
fprintf(stderr, "Can't open %s\n", train_image_name);
exit(1);
}
if ((ftln = fopen(train_label_name, "wb")) == NULL){
fprintf(stderr, "Can't open %s\n", train_label_name);
exit(1);
}
// Writed header
buf[0] = htonl(0x803); // magic number
buf[1] = htonl((STRAIGHT_NUM_OF_IMAGE+LEFT_TURN_NUM_OF_IMAGE+RIGHT_TURN_NUM_OF_IMAGE)*25); // number of image
buf[2] = htonl(10); // number of rows (10)
buf[3] = htonl(56); // number of columns (56)
fwrite(buf, sizeof(uint32_t), 4, ftin);
buf[0] = htonl(0x801); // magic number
buf[1] = htonl((STRAIGHT_NUM_OF_IMAGE+LEFT_TURN_NUM_OF_IMAGE+RIGHT_TURN_NUM_OF_IMAGE)*25); // number of image
fwrite(buf, sizeof(uint32_t), 2, ftln);
// refereed to http://opencv.jp/cookbook/opencv_img.html
// straight
for(int i=0; i<STRAIGHT_NUM_OF_IMAGE; i++){
sprintf(bmp_file, "%s%d.bmp", straight_fn, i);
cv::Mat straight_img = cv::imread(bmp_file,1);
if(straight_img.empty())
return(-1);
cv::Mat reduct_img(straight_img.rows*0.075, straight_img.cols*0.075, straight_img.type());
cv::resize(straight_img, reduct_img, reduct_img.size(), cv::INTER_LINEAR);
cv::Mat gray_img;
cv::cvtColor(reduct_img, gray_img, CV_BGR2GRAY);
sprintf(bmp_file, "%s_RED%d.bmp", straight_fn, i);
cv::imwrite(bmp_file, gray_img);
for(int y=0; y<5; y++){
for(int x=0; x<5; x++){
cv::Rect rect_center(x, 30+y, 56, 10);
cv::Mat img_rect(gray_img, rect_center);
sprintf(bmp_file, "%s_RED_rect%d_%d%d.bmp", straight_fn, i, y, x);
cv::imwrite(bmp_file, img_rect);
for(int iy=0; iy<img_rect.rows; iy++){
for(int ix=0; ix<img_rect.cols; ix++){
bufchar[ix] = img_rect.at<uchar>(iy, ix);
}
fwrite(bufchar, sizeof(uint8_t), img_rect.cols, ftin); // image write
}
bufchar[0] = 0x1;
fwrite(bufchar, sizeof(uint8_t), 1, ftln); // label write
}
}
}
// left turn
for(int i=0; i<LEFT_TURN_NUM_OF_IMAGE; i++){
sprintf(bmp_file, "%s%d.bmp", left_turn_fn, i);
cv::Mat left_turn_img = cv::imread(bmp_file,1);
if(left_turn_img.empty())
return(-1);
cv::Mat reduct_img(left_turn_img.rows*0.075, left_turn_img.cols*0.075, left_turn_img.type());
cv::resize(left_turn_img, reduct_img, reduct_img.size(), cv::INTER_LINEAR);
cv::Mat gray_img;
cv::cvtColor(reduct_img, gray_img, CV_BGR2GRAY);
sprintf(bmp_file, "%s_RED%d.bmp", left_turn_fn, i);
cv::imwrite(bmp_file, gray_img);
for(int y=0; y<5; y++){
for(int x=0; x<5; x++){
cv::Rect rect_center(x, 30+y, 56, 10);
cv::Mat img_rect(gray_img, rect_center);
sprintf(bmp_file, "%s_RED_rect%d_%d%d.bmp", left_turn_fn, i, y, x);
cv::imwrite(bmp_file, img_rect);
for(int iy=0; iy<img_rect.rows; iy++){
for(int ix=0; ix<img_rect.cols; ix++){
bufchar[ix] = img_rect.at<uchar>(iy, ix);
}
fwrite(bufchar, sizeof(uint8_t), img_rect.cols, ftin); // image write
}
bufchar[0] = 0x0;
fwrite(bufchar, sizeof(uint8_t), 1, ftln); // label write
}
}
}
// right turn
for(int i=0; i<RIGHT_TURN_NUM_OF_IMAGE; i++){
sprintf(bmp_file, "%s%d.bmp", right_turn_fn, i);
cv::Mat right_turn_img = cv::imread(bmp_file,1);
if(right_turn_img.empty())
return(-1);
cv::Mat reduct_img(right_turn_img.rows*0.075, right_turn_img.cols*0.075, right_turn_img.type());
cv::resize(right_turn_img, reduct_img, reduct_img.size(), cv::INTER_LINEAR);
cv::Mat gray_img;
cv::cvtColor(reduct_img, gray_img, CV_BGR2GRAY);
sprintf(bmp_file, "%s_RED%d.bmp", right_turn_fn, i);
cv::imwrite(bmp_file, gray_img);
for(int y=0; y<5; y++){
for(int x=0; x<5; x++){
cv::Rect rect_center(x, 30+y, 56, 10);
cv::Mat img_rect(gray_img, rect_center);
sprintf(bmp_file, "%s_RED_rect%d_%d%d.bmp", right_turn_fn, i, y, x);
cv::imwrite(bmp_file, img_rect);
for(int iy=0; iy<img_rect.rows; iy++){
for(int ix=0; ix<img_rect.cols; ix++){
bufchar[ix] = img_rect.at<uchar>(iy, ix);
}
fwrite(bufchar, sizeof(uint8_t), img_rect.cols, ftin); // image write
}
bufchar[0] = 0x2;
fwrite(bufchar, sizeof(uint8_t), 1, ftln); // label write
}
}
}
fclose(ftin);
fclose(ftln);
return(0);
}
// straight_dataset_bmp.h
// 2017/07/24 by marsee
//
#ifndef __STRAIGHT_DATASET_BMP_H__
#define __STRAIGHT_DATASET_BMP_H__
#include "hls_video.h"
#define BMP_HEIGHT 600
#define BMP_WIDTH 800
#define REDUCTION_RATIO 0.075 // 1/13.3333... 60x45
#define DATASET_HEIGHT 10
#define DATASET_WIDTH 56
#define STRAIGHT_BMP_FILE_NAME straight
#define LEFT_TURN_BMP_FILE_NAME left_turn
#define RIGHT_TURN_BMP_FILE_NAME right_turn
#define STRAIGHT_NUM_OF_IMAGE 11
#define LEFT_TURN_NUM_OF_IMAGE 11
#define RIGHT_TURN_NUM_OF_IMAGE 11
typedef hls::Scalar<3, unsigned char> RGB_PIXEL;
typedef hls::Mat<BMP_HEIGHT, BMP_WIDTH, HLS_8UC3> RGB_IMAGE;
typedef hls::Mat<BMP_HEIGHT, BMP_WIDTH, HLS_8UC1> GRAY_IMAGE;
#endif
TRAINING SET LABEL FILE (train-labels-idx1-ubyte):
[offset] [type] [value] [description]
0000 32 bit integer 0x00000801(2049) magic number (MSB first)
0004 32 bit integer 60000 number of items
0008 unsigned byte ?? label
0009 unsigned byte ?? label
........
xxxx unsigned byte ?? label
The labels values are 0 to 9.
TRAINING SET IMAGE FILE (train-images-idx3-ubyte):
[offset] [type] [value] [description]
0000 32 bit integer 0x00000803(2051) magic number
0004 32 bit integer 60000 number of images
0008 32 bit integer 28 number of rows
0012 32 bit integer 28 number of columns
0016 unsigned byte ?? pixel
0017 unsigned byte ?? pixel
........
xxxx unsigned byte ?? pixel
Pixels are organized row-wise. Pixel values are 0 to 255. 0 means background (white), 255 means foreground (black).
TEST SET LABEL FILE (t10k-labels-idx1-ubyte):
[offset] [type] [value] [description]
0000 32 bit integer 0x00000801(2049) magic number (MSB first)
0004 32 bit integer 10000 number of items
0008 unsigned byte ?? label
0009 unsigned byte ?? label
........
xxxx unsigned byte ?? label
The labels values are 0 to 9.
TEST SET IMAGE FILE (t10k-images-idx3-ubyte):
[offset] [type] [value] [description]
0000 32 bit integer 0x00000803(2051) magic number
0004 32 bit integer 10000 number of images
0008 32 bit integer 28 number of rows
0012 32 bit integer 28 number of columns
0016 unsigned byte ?? pixel
0017 unsigned byte ?? pixel
........
xxxx unsigned byte ?? pixel
Pixels are organized row-wise. Pixel values are 0 to 255. 0 means background (white), 255 means foreground (black).
1. 800x600の白線画像を1/13.333...(0.075)の60x45に縮める。
2. 60x45のうちの下から60x14を中間BMPファイルとしてセーブ
3. 60x14のうちの56x10を切り出してBMPファイルに。1つにつき5x5の25個できる。
4. 左右直進をやる。
直進10枚x25+左旋回10x25+右旋回10x25=750このデータセットをとりあえず、作ってみようか?
56x10=560なのでMNISTデータセットよりも小さくなる。
// straight_dataset_bmp.h
// 2017/07/24 by marsee
//
#ifndef __STRAIGHT_DATASET_BMP_H__
#define __STRAIGHT_DATASET_BMP_H__
#include "hls_video.h"
#define BMP_HEIGHT 600
#define BMP_WIDTH 800
#define REDUCTION_RATIO 0.075 // 1/13.3333... 60x45
#define DATASET_HEIGHT 10
#define DATASET_WIDTH 56
#define STRAIGHT_BMP_FILE_NAME straight
#define LEFT_TRUN_BMP_FILE_NAME left_turn
#define RIGHT_TRUN_BMP_FILE_NAME right_turn
#define STRAIGHT_NUM_OF_IMAGE 10
#define LEFT_TRUN_NUM_OF_IMAGE 10
#define RIGHT_TRUNNUM_OF_IMAGE 10
typedef hls::Scalar<3, unsigned char> RGB_PIXEL;
typedef hls::Mat<BMP_HEIGHT, BMP_WIDTH, HLS_8UC3> RGB_IMAGE;
typedef hls::Mat<BMP_HEIGHT, BMP_WIDTH, HLS_8UC1> GRAY_IMAGE;
#endif
// 2017/07/24 by marsee
//
#include <iostream>
#include "hls_opencv.h"
#include "straight_dataset_bmp.h"
int main(){
char straight_fn[256] = "straight";
char left_turn_fn[256] = "left_turn";
char right_turn_fn[256] = "right_turn";
char bmp_file[256];
cv::Rect rect_center(2, 33, 56, 10);
// refereed to http://opencv.jp/cookbook/opencv_img.html
// straight
for(int i=0; i<STRAIGHT_NUM_OF_IMAGE; i++){
sprintf(bmp_file, "%s%d.bmp", straight_fn, i);
cv::Mat straight_img = cv::imread(bmp_file,1);
if(straight_img.empty())
return(-1);
cv::Mat reduct_img(straight_img.rows*0.075, straight_img.cols*0.075, straight_img.type());
cv::resize(straight_img, reduct_img, reduct_img.size(), cv::INTER_LINEAR);
cv::Mat gray_img;
cv::cvtColor(reduct_img, gray_img, CV_BGR2GRAY);
sprintf(bmp_file, "%s_RED%d.bmp", straight_fn, i);
cv::imwrite(bmp_file, gray_img);
cv::Rect rect_center(2, 33, 56, 10);
cv::Mat img_rect(gray_img, rect_center);
sprintf(bmp_file, "%s_RED_rect%d.bmp", straight_fn, i);
cv::imwrite(bmp_file, img_rect);
}
return(0);
}
日 | 月 | 火 | 水 | 木 | 金 | 土 |
---|---|---|---|---|---|---|
- | - | 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | - | - |