使用旧版候选区寻找方式。

This commit is contained in:
xinyang
2019-05-02 20:19:17 +08:00
parent ee83a373d3
commit 2f20367677
20 changed files with 12502 additions and 12395 deletions

View File

@@ -13,8 +13,7 @@
void showArmorBoxVector(std::string windows_name, const cv::Mat &src, const std::vector<cv::Rect2d> &armor_box); void showArmorBoxVector(std::string windows_name, const cv::Mat &src, const std::vector<cv::Rect2d> &armor_box);
void showArmorBox(std::string windows_name, const cv::Mat &src, cv::Rect2d armor_box); void showArmorBox(std::string windows_name, const cv::Mat &src, cv::Rect2d armor_box);
void showContours(std::string windows_name, const cv::Mat &src, const std::vector<LightBlob> &light_blobs); void showContours(std::string windows_name, const cv::Mat &src, const std::vector<LightBlob> &light_blobs);
void showArmorBoxClass(std::string window_names, const cv::Mat &src, vector<cv::Rect2d> boxes_one, void showArmorBoxClass(std::string window_names, const cv::Mat &src, vector<cv::Rect2d> boxes[10]);
vector<cv::Rect2d> boxes_two, vector<cv::Rect2d> boxes_three);
#endif /* _SHOW_IMAGES_H_ */ #endif /* _SHOW_IMAGES_H_ */

View File

@@ -1,6 +1,7 @@
// //
// Created by xinyang on 19-3-27. // Created by xinyang on 19-3-27.
// //
#define LOG_LEVEL LOG_NONE
#include <log.h> #include <log.h>
#include <options/options.h> #include <options/options.h>
#include <show_images/show_images.h> #include <show_images/show_images.h>
@@ -40,14 +41,14 @@ void ArmorFinder::run(cv::Mat &src) {
tracker = TrackerToUse::create(); tracker = TrackerToUse::create();
tracker->init(src_use, armor_box); tracker->init(src_use, armor_box);
state = TRACKING_STATE; state = TRACKING_STATE;
LOGW("into track"); LOGM(STR_CTR(WORD_LIGHT_CYAN, "into track"));
} }
} }
break; break;
case TRACKING_STATE: case TRACKING_STATE:
if(!stateTrackingTarget(src_use)){ if(!stateTrackingTarget(src_use)){
state = SEARCHING_STATE; state = SEARCHING_STATE;
//std::cout << "into search!" << std::endl; LOGM(STR_CTR(WORD_LIGHT_YELLOW ,"into search!"));
} }
break; break;
case STANDBY_STATE: case STANDBY_STATE:
@@ -59,11 +60,14 @@ void ArmorFinder::run(cv::Mat &src) {
#define FOCUS_PIXAL (0.36/0.48*640) #define FOCUS_PIXAL (0.36/0.48*640)
bool ArmorFinder::sendBoxPosition() { bool ArmorFinder::sendBoxPosition() {
static int dx_add = 0;
auto rect = armor_box; auto rect = armor_box;
double dx = rect.x + rect.width/2 - 320; double dx = rect.x + rect.width/2 - 320 - 8;
double dy = rect.y + rect.height/2 - 240; dx_add += dx;
dx = dx + dx_add * 0;
double dy = rect.y + rect.height/2 - 240 - 30;
double yaw = atan(dx / FOCUS_PIXAL) * 180 / 3.14159265459; double yaw = atan(dx / FOCUS_PIXAL) * 180 / 3.14159265459;
double pitch = atan(dy / FOCUS_PIXAL) * 180 / 3.14159265459; double pitch = atan(dy / FOCUS_PIXAL) * 180 / 3.14159265459;
uart.sendTarget(yaw, pitch, 0); uart.sendTarget(yaw, -pitch, 0);
return true; return true;
} }

View File

@@ -92,7 +92,7 @@ MatrixXd Classifier::softmax(const MatrixXd &input){
return tmp.array().exp() / tmp.array().exp().sum(); return tmp.array().exp() / tmp.array().exp().sum();
} }
vector<vector<MatrixXd>> max_pool(const vector<vector<MatrixXd>> &input, int size){ vector<vector<MatrixXd>> Classifier::max_pool(const vector<vector<MatrixXd>> &input, int size){
vector<vector<MatrixXd>> output; vector<vector<MatrixXd>> output;
for(int sample=0; sample<input.size(); sample++) { for(int sample=0; sample<input.size(); sample++) {
vector<MatrixXd> sub; vector<MatrixXd> sub;

View File

@@ -31,10 +31,15 @@ static void pipelineLightBlobPreprocess(cv::Mat &src) {
} }
static bool findLightBlobs(const cv::Mat &src, LightBlobs &light_blobs) { static bool findLightBlobs(const cv::Mat &src, LightBlobs &light_blobs) {
// static cv::Mat src_bin; static cv::Mat src_gray, src_bin;
if(src.type() == CV_8UC3){
cvtColor(src, src_gray, CV_BGR2GRAY);
}else if(src.type() == CV_8UC1){
src_gray = src.clone();
}
std::vector<std::vector<cv::Point> > light_contours; std::vector<std::vector<cv::Point> > light_contours;
cv::findContours(src, light_contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); cv::findContours(src_gray, light_contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
for (auto &light_contour : light_contours) { for (auto &light_contour : light_contours) {
cv::RotatedRect rect = cv::minAreaRect(light_contour); cv::RotatedRect rect = cv::minAreaRect(light_contour);
if(isValidLightBlob(rect)){ if(isValidLightBlob(rect)){
@@ -114,8 +119,8 @@ static bool findArmorBoxes(LightBlobs &light_blobs, std::vector<cv::Rect2d> &arm
double min_x, min_y, max_x, max_y; double min_x, min_y, max_x, max_y;
min_x = fmin(rect_left.x, rect_right.x); min_x = fmin(rect_left.x, rect_right.x);
max_x = fmax(rect_left.x + rect_left.width, rect_right.x + rect_right.width); max_x = fmax(rect_left.x + rect_left.width, rect_right.x + rect_right.width);
min_y = fmin(rect_left.y, rect_right.y) - 5; min_y = fmin(rect_left.y, rect_right.y) - 3;
max_y = fmax(rect_left.y + rect_left.height, rect_right.y + rect_right.height); max_y = fmax(rect_left.y + rect_left.height, rect_right.y + rect_right.height) + 3;
if (min_x < 0 || max_x > 640 || min_y < 0 || max_y > 480) { if (min_x < 0 || max_x > 640 || min_y < 0 || max_y > 480) {
continue; continue;
} }
@@ -147,31 +152,42 @@ bool judge_light_color(std::vector<LightBlob> &light, std::vector<LightBlob> &co
} }
bool ArmorFinder::stateSearchingTarget(cv::Mat &src) { bool ArmorFinder::stateSearchingTarget(cv::Mat &src) {
cv::Mat split, pmsrc=src.clone(), src_bin; cv::Mat split, src_bin;
LightBlobs light_blobs, pm_light_blobs, light_blobs_real; LightBlobs light_blobs, light_blobs_, light_blobs_real;
std::vector<cv::Rect2d> armor_boxes, boxes_one, boxes_two, boxes_three; std::vector<cv::Rect2d> armor_boxes, boxes_number[9];
armor_box = cv::Rect2d(0,0,0,0);
// cv::resize(src, pmsrc, cv::Size(320, 240)); cv::cvtColor(src, src_gray, CV_BGR2GRAY);
imageColorSplit(src, split, enemy_color); // pipelineLightBlobPreprocess(src_gray);
cv::threshold(split, src_bin, 130, 255, CV_THRESH_BINARY); cv::threshold(src_gray, src_bin, 120, 255, CV_THRESH_BINARY);
imagePreProcess(src_bin);
// cv::imshow("bin", src_bin);
// cv::resize(split, split, cv::Size(640, 480));
// pipelineLightBlobPreprocess(pmsrc);
// if(!findLightBlobs(pmsrc, pm_light_blobs)){
// return false;
// }
if(!findLightBlobs(src_bin, light_blobs)){ if(!findLightBlobs(src_bin, light_blobs)){
return false; return false;
} }
// if(!judge_light_color(light_blobs, pm_light_blobs, light_blobs_real)){
// return false;
// }
if(show_light_blobs){ if(show_light_blobs){
showContours("blobs", split, light_blobs); showContours("blobs", src_bin, light_blobs);
cv::waitKey(1); cv::waitKey(1);
} }
if(!findArmorBoxes(light_blobs, armor_boxes)){
imageColorSplit(src, split, enemy_color);
imagePreProcess(split);
cv::threshold(split, src_bin, 120, 255, CV_THRESH_BINARY);
if(!findLightBlobs(src_bin, light_blobs_)){
return false;
}
if(show_light_blobs){
showContours("blobs_", src_bin, light_blobs_);
cv::waitKey(1);
}
if(!judge_light_color(light_blobs, light_blobs_, light_blobs_real)){
return false;
}
if(show_light_blobs){
showContours("blobs_real", src, light_blobs_real);
cv::waitKey(1);
}
if(!findArmorBoxes(light_blobs_real, armor_boxes)){
return false; return false;
} }
if(show_armor_boxes){ if(show_armor_boxes){
@@ -183,29 +199,21 @@ bool ArmorFinder::stateSearchingTarget(cv::Mat &src) {
cv::Mat roi = src(box).clone(); cv::Mat roi = src(box).clone();
cv::resize(roi, roi, cv::Size(48, 36)); cv::resize(roi, roi, cv::Size(48, 36));
int c = classifier(roi); int c = classifier(roi);
switch(c){ if(c){
case 1: boxes_number[c-1].emplace_back(box);
boxes_one.emplace_back(box);
break;
case 2:
boxes_two.emplace_back(box);
break;
case 3:
boxes_three.emplace_back(box);
break;
} }
} }
if(!boxes_one.empty()){ for(auto box : boxes_number){
armor_box = boxes_one[0]; if(!box.empty()){
}else if(!boxes_two.empty()){ armor_box = box[0];
armor_box = boxes_two[0]; }
}else if(!boxes_three.empty()){ }
armor_box = boxes_three[0];
} else{ if(armor_box == cv::Rect2d(0,0,0,0)){
return false; return false;
} }
if(show_armor_box){ if(show_armor_boxes){
showArmorBoxClass("class", src, boxes_one, boxes_two, boxes_three); showArmorBoxClass("class", src, boxes_number);
} }
}else{ }else{
armor_box = armor_boxes[0]; armor_box = armor_boxes[0];

View File

@@ -18,8 +18,7 @@ void showArmorBoxVector(std::string windows_name, const cv::Mat &src, const std:
imshow(windows_name, image2show); imshow(windows_name, image2show);
} }
void showArmorBoxClass(std::string windows_name, const cv::Mat &src, vector<cv::Rect2d> boxes_one, void showArmorBoxClass(std::string window_names, const cv::Mat &src, vector<cv::Rect2d> boxes[10]){
vector<cv::Rect2d> boxes_two, vector<cv::Rect2d> boxes_three){
static Mat image2show; static Mat image2show;
if (src.type() == CV_8UC1) // 黑白图像 if (src.type() == CV_8UC1) // 黑白图像
{ {
@@ -28,16 +27,32 @@ void showArmorBoxClass(std::string windows_name, const cv::Mat &src, vector<cv::
{ {
image2show = src.clone(); image2show = src.clone();
} }
for (auto &box:boxes_one) { if(!boxes[0].empty()){
rectangle(image2show, box, Scalar(255, 0, 0), 1); for(auto box : boxes[0]){
cv::rectangle(image2show, box, Scalar(255, 0, 0), 1);
} }
for (auto &box:boxes_two) { }else if(!boxes[1].empty()){
rectangle(image2show, box, Scalar(0, 255, 0), 1); for(auto box : boxes[1]){
cv::rectangle(image2show, box, Scalar(0, 255, 0), 1);
} }
for (auto &box:boxes_three) { }else if(!boxes[2].empty()){
rectangle(image2show, box, Scalar(0, 0, 255), 1); for(auto box : boxes[2]){
cv::rectangle(image2show, box, Scalar(0, 0, 255), 1);
} }
imshow(windows_name, image2show); }else if(!boxes[3].empty()){
for(auto box : boxes[3]){
cv::rectangle(image2show, box, Scalar(0, 255, 255), 1);
}
}else if(!boxes[4].empty()){
for(auto box : boxes[4]){
cv::rectangle(image2show, box, Scalar(255, 0, 255), 1);
}
}else if(!boxes[5].empty()){
for(auto box : boxes[5]){
cv::rectangle(image2show, box, Scalar(255, 255, 0), 1);
}
}
imshow(window_names, image2show);
} }
void showArmorBox(std::string windows_name, const cv::Mat &src, cv::Rect2d armor_box) { void showArmorBox(std::string windows_name, const cv::Mat &src, cv::Rect2d armor_box) {

View File

@@ -15,7 +15,7 @@
#include <options/options.h> #include <options/options.h>
#include <thread> #include <thread>
//#define DO_NOT_CNT_TIME #define DO_NOT_CNT_TIME
#include <log.h> #include <log.h>
#define PATH PROJECT_DIR #define PATH PROJECT_DIR
@@ -33,12 +33,23 @@ int mark = 0;
void uartReceive(Uart* uart); void uartReceive(Uart* uart);
thread* create_data_recv_thread(Uart *uart){
thread *thread1 = new thread([uart](){
LOGM("Start receiving!");
while(1){
uart->debugUart();
}
});
return thread1;
}
int main(int argc, char *argv[]){ int main(int argc, char *argv[]){
process_options(argc, argv); process_options(argc, argv);
Uart uart; Uart uart;
thread receive(uartReceive, &uart); thread receive(uartReceive, &uart);
bool flag = true; bool flag = true;
// create_data_recv_thread(&uart);
while (flag){ while (flag){
int ally_color = ALLY_RED; int ally_color = ALLY_RED;
int energy_part_rotation = CLOCKWISE; int energy_part_rotation = CLOCKWISE;
@@ -55,8 +66,8 @@ int main(int argc, char *argv[]){
video_armor = new CameraWrapper(0); video_armor = new CameraWrapper(0);
// video_energy = new CameraWrapper(1); // video_energy = new CameraWrapper(1);
}else { }else {
video_armor = new VideoWrapper("/home/xinyang/Desktop/Video.mp4"); video_armor = new VideoWrapper("/home/xinyang/Desktop/Video0.mp4");
video_energy = new VideoWrapper("/home/xinyang/Desktop/Video.mp4"); video_energy = new VideoWrapper("/home/xinyang/Desktop/Video0.mp4");
} }
if (video_armor->init()) { if (video_armor->init()) {
cout << "Video source initialization successfully." << endl; cout << "Video source initialization successfully." << endl;
@@ -74,11 +85,10 @@ int main(int argc, char *argv[]){
while (ok){ while (ok){
CNT_TIME(WORD_LIGHT_CYAN, "Total", { CNT_TIME(WORD_LIGHT_CYAN, "Total", {
ok = video_armor->read(energy_src) && video_armor->read(armor_src); CNT_TIME(WORD_LIGHT_PURPLE, "Read", {
if (show_origin) { ok = video_armor->read(armor_src);
imshow("enery src", energy_src); // ok &&= video_energy->read(energy_src);
imshow("armor src", armor_src); });
}
if (state == ENERGY_STATE) { if (state == ENERGY_STATE) {
if (from_camera == 0) { if (from_camera == 0) {
energy.extract(energy_src); energy.extract(energy_src);
@@ -112,6 +122,7 @@ void uartReceive(Uart* uart){
buffer[cnt++] = data; buffer[cnt++] = data;
if(cnt >= 100){ if(cnt >= 100){
// LOGE("data receive over flow!"); // LOGE("data receive over flow!");
cnt = 0;
} }
} }
if(cnt == 10){ if(cnt == 10){
@@ -131,7 +142,6 @@ void uartReceive(Uart* uart){
mark_yaw = curr_yaw; mark_yaw = curr_yaw;
mark_pitch = curr_pitch; mark_pitch = curr_pitch;
} }
// LOGM("Marked"); // LOGM("Marked");
} }
} }

View File

@@ -36,6 +36,7 @@ public:
uint8_t receive(); uint8_t receive();
void receive_data(); void receive_data();
bool debugUart();
}; };

View File

@@ -65,11 +65,14 @@ stop:
tCapability.sResolutionRange.iWidthMax * 3); tCapability.sResolutionRange.iWidthMax * 3);
if(mode == 0){ if(mode == 0){
// 不使用自动曝光 // 不使用自动曝光
CameraSetAeState(h_camera, true); CameraSetAeState(h_camera, false);
// 曝光时间10ms // 曝光时间10ms
// CameraSetExposureTime(h_camera, 10000); CameraSetExposureTime(h_camera, 10000);
double t;
CameraGetExposureTime(h_camera, &t);
LOGM("Exposure time: %lfms", t/1000.0);
// 模拟增益4 // 模拟增益4
CameraSetAnalogGain(h_camera, 64); CameraSetAnalogGain(h_camera, 55);
// 使用预设LUT表 // 使用预设LUT表
CameraSetLutMode(h_camera, LUTMODE_PRESET); CameraSetLutMode(h_camera, LUTMODE_PRESET);
// 抗频闪 // 抗频闪
@@ -90,7 +93,7 @@ stop:
/*其他的相机参数设置 /*其他的相机参数设置
例如 CameraSetExposureTime CameraGetExposureTime 设置/读取曝光时间 例如 CameraSetExposureTime CameraGetExposureTime 设置/读取曝光时间
CameraSetImageResolution CameraGetImageResolution 设置/读取分辨率 CameraSetImageResolution CameraGetImageResolution 设置/读取分辨率
CameraSetGamma、CameraSetConrast、CameraSetGain等设置图像伽马、对比度、RGB数字增益等等。 CameraSetGamma、CameraSetContrast、CameraSetGain等设置图像伽马、对比度、RGB数字增益等等。
CameraGetFriendlyName CameraSetFriendlyName 获取/设置相机名称(该名称可写入相机硬件) CameraGetFriendlyName CameraSetFriendlyName 获取/设置相机名称(该名称可写入相机硬件)
*/ */

View File

@@ -4,6 +4,7 @@
#include <uart/uart.h> #include <uart/uart.h>
#include <energy/param_struct_define.h> #include <energy/param_struct_define.h>
#include <log.h>
using std::cout; using std::cout;
using std::cerr; using std::cerr;
@@ -16,7 +17,6 @@ GMAngle_t aim;
Uart::Uart(){ Uart::Uart(){
fd = open("/dev/ttyUSB0", O_RDWR); fd = open("/dev/ttyUSB0", O_RDWR);
if(fd < 0) if(fd < 0)
{ {
@@ -121,6 +121,9 @@ int Uart::set_opt(int fd, int nSpeed, int nBits, char nEvent, int nStop) {
return 0; return 0;
} }
FILE *send_info=fopen("send.info", "w");
FILE *recv_info=fopen("recv.info", "w");
void Uart::sendTarget(float x, float y, float z) { void Uart::sendTarget(float x, float y, float z) {
static short x_tmp, y_tmp, z_tmp; static short x_tmp, y_tmp, z_tmp;
@@ -146,6 +149,13 @@ void Uart::sendTarget(float x, float y, float z) {
buff[6] = static_cast<char>((z_tmp >> 0) & 0xFF); buff[6] = static_cast<char>((z_tmp >> 0) & 0xFF);
buff[7] = 'e'; buff[7] = 'e';
timeval ts;
gettimeofday(&ts, NULL);
fprintf(send_info, "%lf %f %f\n",
ts.tv_sec + ts.tv_usec / 1e6,
x, y
);
write(fd, buff, 8); write(fd, buff, 8);
} }
@@ -159,3 +169,28 @@ uint8_t Uart::receive() {
return data; return data;
} }
void readall(int fd, void* buff, int size) {
int cnt = 0;
while ((cnt += read(fd, (char*)buff + cnt, size - cnt)) < size);
}
char readone(int fd){
char val;
while(read(fd, &val, 1) < 1);
return val;
}
bool Uart::debugUart() {
float val[3];
//while(readone(fd) != 's');
readall(fd, val, sizeof(val));
timeval ts;
gettimeofday(&ts, NULL);
fprintf(recv_info, "%lf %f %f %f\n",
ts.tv_sec + ts.tv_usec / 1e6,
val[0], val[1], val[2]
);
}

View File

@@ -53,7 +53,7 @@ def save_para(folder, paras):
save_bias(fp, paras[7]) save_bias(fp, paras[7])
STEPS = 20000 STEPS = 10000
BATCH = 30 BATCH = 30
LEARNING_RATE_BASE = 0.01 LEARNING_RATE_BASE = 0.01
LEARNING_RATE_DECAY = 0.99 LEARNING_RATE_DECAY = 0.99
@@ -61,8 +61,6 @@ MOVING_AVERAGE_DECAY = 0.99
def train(dataset, show_bar=False): def train(dataset, show_bar=False):
test_images, test_labels = dataset.all_test_sets()
x = tf.placeholder(tf.float32, [None, generate.SRC_ROWS, generate.SRC_COLS, generate.SRC_CHANNELS]) x = tf.placeholder(tf.float32, [None, generate.SRC_ROWS, generate.SRC_COLS, generate.SRC_CHANNELS])
y_= tf.placeholder(tf.float32, [None, forward.OUTPUT_NODES]) y_= tf.placeholder(tf.float32, [None, forward.OUTPUT_NODES])
nodes, vars = forward.forward(x, 0.001) nodes, vars = forward.forward(x, 0.001)
@@ -104,7 +102,8 @@ def train(dataset, show_bar=False):
if i % 100 == 0: if i % 100 == 0:
if i % 1000 == 0: if i % 1000 == 0:
acc = sess.run(accuracy, feed_dict={x: test_images, y_: test_labels}) test_samples, test_labels = dataset.sample_train_sets(5000)
acc = sess.run(accuracy, feed_dict={x: test_samples, y_: test_labels})
bar.set_postfix({"loss": loss_value, "acc": acc}) bar.set_postfix({"loss": loss_value, "acc": acc})
@@ -151,8 +150,8 @@ def train(dataset, show_bar=False):
vars_val = sess.run(vars) vars_val = sess.run(vars)
save_para("/home/xinyang/Desktop/AutoAim/tools/para", vars_val) save_para("/home/xinyang/Desktop/AutoAim/tools/para", vars_val)
nodes_val = sess.run(nodes, feed_dict={x:test_images}) nodes_val = sess.run(nodes, feed_dict={x:test_samples})
return vars_val, nodes_val return vars_val, nodes_val, test_samples
if __name__ == "__main__": if __name__ == "__main__":
@@ -160,3 +159,4 @@ if __name__ == "__main__":
dataset = generate.DataSet("/home/xinyang/Desktop/DataSets/box") dataset = generate.DataSet("/home/xinyang/Desktop/DataSets/box")
print("Finish!") print("Finish!")
train(dataset, show_bar=True) train(dataset, show_bar=True)
input("Press any key to continue...")

View File

@@ -24,34 +24,40 @@ class DataSet:
self.test_labels = [] self.test_labels = []
self.generate_data_sets(folder) self.generate_data_sets(folder)
def file2nparray(self, name): def generate_data_sets(self, folder):
try: def id2label(id):
image = cv2.imread(name)
image = cv2.resize(image, (SRC_COLS, SRC_ROWS))
image = image.astype(np.float32)
return image / 255.0
except:
print(name)
sys.exit(-1)
def id2label(self, id):
a = np.zeros([OUTPUT_NODES]) a = np.zeros([OUTPUT_NODES])
a[id] = 1 a[id] = 1
return a[:] return a[:]
def generate_data_sets(self, folder): def file2nparray(name):
try:
image = cv2.imread(name)
if image.shape[0] < 15:
return None
elif image.shape[1] < 10:
return None
image = cv2.resize(image, (SRC_COLS, SRC_ROWS))
image = image.astype(np.float32)
return image / 255.0, id2label(int(name.split("/")[-2]))
except TypeError:
print(name)
sys.exit(-1)
sets = [] sets = []
for i in range(OUTPUT_NODES): for i in range(OUTPUT_NODES):
dir = "%s/%d" % (folder, i) dir = "%s/%d" % (folder, i)
files = os.listdir(dir) files = os.listdir(dir)
for file in tqdm(files, postfix={"loading id": i}, dynamic_ncols=True): for file in tqdm(files, postfix={"loading id": i}, dynamic_ncols=True):
if file[-3:] == "jpg": if file[-3:] == "jpg":
x = file2nparray("%s/%s" % (dir, file))
if x is not None:
if random.random() > 0.2: if random.random() > 0.2:
self.train_samples.append(self.file2nparray("%s/%s" % (dir, file))) self.train_samples.append(x[0])
self.train_labels.append(self.id2label(i)) self.train_labels.append(x[1])
else: else:
self.test_samples.append(self.file2nparray("%s/%s" % (dir, file))) self.test_samples.append(x[0])
self.test_labels.append(self.id2label(i)) self.test_labels.append(x[1])
self.train_samples = np.array(self.train_samples) self.train_samples = np.array(self.train_samples)
self.train_labels = np.array(self.train_labels) self.train_labels = np.array(self.train_labels)
self.test_samples = np.array(self.test_samples) self.test_samples = np.array(self.test_samples)
@@ -67,6 +73,15 @@ class DataSet:
labels.append(self.train_labels[id]) labels.append(self.train_labels[id])
return np.array(samples), np.array(labels) return np.array(samples), np.array(labels)
def sample_test_sets(self, length):
samples = []
labels = []
for i in range(length):
id = random.randint(0, len(self.test_samples)-1)
samples.append(self.test_samples[id])
labels.append(self.test_labels[id])
return np.array(samples), np.array(labels)
def all_train_sets(self): def all_train_sets(self):
return self.train_samples[:], self.train_labels[:] return self.train_samples[:], self.train_labels[:]

View File

@@ -1,7 +1,7 @@
6 6
0.6241298 -0.37225634
1.1128483 -0.2478522
0.92715627 -0.47375765
2.6803706 0.009908229
-2.4037633 0.69579834
1.6914424 -0.05971829

View File

@@ -2,453 +2,453 @@
6 6
5 5
5 5
-1.8745673 -0.7337494
-1.4418055 -0.6937527
-0.68810487 -0.67101884
-0.42730802 -0.60440236
-0.019043377 -0.73606586
-2.2401865 -0.7478304
-1.5337001 -0.8085305
-0.5666739 -0.6904055
0.1119876 -0.7651195
0.24716255 -0.7084718
-2.2945662 -0.9906155
-1.4734446 -0.87745357
-0.298631 -0.7000051
0.19550888 -0.8715864
0.45057848 -0.7446616
-2.4559898 -0.8037889
-1.097164 -0.618627
-0.035884537 -0.6325674
0.23402216 -0.59341496
0.3693794 -0.62959474
-1.7285618 -0.014231296
-0.8927671 -0.08161524
0.026205042 -0.2579513
0.19274746 -0.4687266
0.029146997 -0.24779701
-1.3690577 -0.22118886
-1.2756748 -0.31540632
-0.32751036 -0.21255392
0.3233031 0.01073099
0.55376107 -0.15033825
-1.4835969 -0.32471213
-1.3036382 -0.12707588
-0.75256515 -0.17916436
-0.13608748 -0.028622292
0.2254278 -0.05188435
-1.6409502 -0.12553264
-1.4188147 -0.0946007
-1.1627024 -0.06460633
-0.62049645 -0.041471746
-0.20085949 0.015563008
-2.2059698 -0.26039425
-1.7030506 -0.079619355
-1.5584862 -0.1205842
-1.2325822 0.094940566
-0.6749467 -0.1750217
-2.8320985 -0.2796452
-2.3289032 -0.19023262
-1.811129 -0.055042416
-1.6702974 -0.050695155
-1.0760157 -0.044094857
-1.3135052 -0.9086073
-0.90016854 -0.35235822
-0.47004116 0.30365855
-0.17118637 1.000589
-0.2732028 1.2184463
-1.3109291 -0.7277262
-0.36519817 -0.27227914
-0.10975292 0.51391685
-0.06533194 0.93604887
-0.559026 1.1217358
-0.8616304 -0.8503647
-0.06857806 -0.1529237
0.19276045 0.7071794
-0.14059812 1.0232986
-0.7283358 0.9231354
-0.57705516 -1.1999215
0.20748538 -0.26001996
0.26281402 0.31989247
-0.112977654 0.49021512
-0.6980696 0.4707462
-0.44812128 -1.3921645
0.40235195 -0.7652607
0.26663 -0.32385713
-0.10336824 -0.0044978694
-0.5741328 0.12107601
-0.70127535 -0.2628682
-1.1506568 -0.040824424
-1.3301972 -0.4928625
-1.4370873 -1.1108128
-0.9951577 -2.1292882
-0.3111034 -0.43092158
-0.5350495 0.039630573
-0.78488415 -0.19942534
-1.3619742 -1.1754087
-1.2252145 -2.0381243
0.10870424 -0.45808747
-0.044690743 0.019034432
-0.33280057 -0.40220654
-1.180621 -1.216894
-1.5130968 -2.1285393
0.32003295 -0.6753537
0.6245109 -0.17457765
0.3391734 -0.19739395
-0.45662346 -0.8989531
-1.2023503 -1.7085532
0.66186905 -0.67778856
0.6943321 -0.2841309
0.753682 -0.20467272
-0.05385303 -0.6957597
-0.69504744 -1.3799949
-0.86241025 -1.221984
0.05611875 -1.047475
0.7984623 -0.5553654
1.4339544 -0.5047841
2.0078037 -0.48746312
-0.6121641 -0.82557076
0.3216552 -0.40178424
0.7244501 -0.14857721
1.4381241 -0.05297258
1.9696213 -0.536673
-0.29659018 -0.5235084
0.13415621 0.052303962
0.61756736 -0.023993408
1.0113128 -0.31840283
1.3834459 -0.9369167
0.12413465 -0.5166214
0.3135587 -0.1376763
0.32853445 0.0063631153
0.7981063 -0.12015801
0.83142936 -1.2773997
-0.004516094 -0.72208375
0.32636595 -0.24810186
0.55108666 -0.26033
0.6248727 -0.46964744
0.60938156 -1.557477
-0.38326544 -0.0126399975
-1.2629062 -0.2124332
-0.385575 0.07490671
0.11398253 -0.08790178
0.40000448 -0.11780411
-1.0602297 0.042807758
-1.1948771 0.008334734
-0.6945023 0.060645778
-0.4127804 -0.14671083
0.029964926 -0.16901183
-1.4086407 -0.22304396
-1.3599807 -0.0769471
-1.3076004 -0.009709285
-1.1330422 -0.14782685
-0.38810351 -0.095943585
-2.1059783 0.020692833
-1.8239182 -0.14911899
-1.7029382 -0.15973799
-1.4902409 -0.03142608
-0.91088384 0.104167305
-3.230572 -0.20708825
-2.4590926 -0.05318397
-1.9471443 -0.07113983
-1.860621 -0.13408132
-1.3370123 -0.11653387
-0.5690341 -0.7500504
-0.33530146 -0.7248431
0.31661218 -0.61835104
0.8375982 -0.45383522
1.1338086 -0.16763654
-1.3648574 -0.61524427
-0.8348736 -0.7349246
0.36666754 -0.8378667
1.1275568 -0.5694857
1.1844105 -0.45536998
-1.8321881 -0.76552916
-0.78104144 -0.851986
0.59508055 -0.85871804
1.2501543 -0.7100276
1.2034286 -0.49703908
-1.6087818 -0.64794004
-0.6121007 -0.50571287
0.693586 -0.6866874
1.2163337 -0.40854928
1.1292332 -0.5622537
-0.6255259 0.07620155
0.0911698 -0.0787729
0.78314143 -0.19114618
0.9095932 -0.16987182
0.5689121 -0.17041641
-3.2688649 -0.27857593
-1.2751737 -0.121658556
0.7530108 -0.085185595
1.5721122 -0.08372851
2.11933 -0.14375111
-2.9633296 -0.37070906
-1.3632398 -0.14901304
0.11986004 -0.054120127
1.1412225 0.038107906
1.8641368 -0.07748371
-1.9467463 -0.20931405
-0.9146176 -0.1937567
-0.10545669 0.14340971
0.49356145 -0.053399563
1.3669914 -0.083370306
-1.7783622 -0.21443273
-0.99905616 -0.080105215
-0.28957212 -0.10266688
0.13239379 0.10945406
0.9921155 -0.18393016
-2.1976538 -0.16443613
-1.0333587 0.017121822
-0.3801185 0.04672509
0.021550074 0.09892883
0.5849712 -0.11781335
-0.7216267 -1.161838
-0.36925313 -0.8175547
-0.5770921 -0.44016403
-0.89754397 0.090491325
-0.9315221 0.8639599
-0.17996566 -0.49316305
0.5721206 0.25248703
0.46629494 0.3574456
-0.11679081 0.791709
-0.8407021 1.0159097
0.14923953 0.108047605
1.1722741 0.72324693
1.0859729 1.0133348
-0.08064234 1.2196273
-1.1707838 0.8379106
0.527985 0.12326059
1.556374 0.6342552
1.3262485 0.91193444
0.052869447 0.69442016
-1.0933924 0.5248603
0.8913072 0.06752323
1.8925939 0.22544046
1.1744183 0.21614142
-0.16056827 -0.033874128
-0.96226853 -0.35373747
-2.0482447 1.2651725
-2.1394062 1.0176816
-2.3160622 0.63459647
-1.5373954 -0.68232757
-1.0280651 -2.055359
-1.0137186 1.2116768
-1.1347228 1.0648314
-1.2650911 0.79537696
-1.3904438 -0.44271514
-1.4724954 -2.0117953
-0.6152145 1.2231245
-0.38191465 1.1929921
-0.6525277 0.5311513
-1.2026839 -0.62809414
-1.574993 -2.1078017
-0.14897716 0.8818138
0.40652698 1.0870899
0.22212738 0.7286623
-0.7051095 -0.21488012
-1.6179065 -1.6681597
0.12883945 0.7761452
0.92052716 1.039942
0.71651196 0.7954326
-0.1521632 0.22737303
-1.3601139 -1.0519534
-1.3278087 -1.4585321
0.091166034 -1.2353656
0.70035547 -1.00755
0.85970676 -0.40541697
1.4728521 -0.241744
-0.4685758 -0.2468871
0.67533374 -0.124388404
1.2041222 0.034186
0.91583323 0.15726992
1.3638756 -0.2593506
-0.21221842 0.21214157
0.46413553 0.60234964
0.6931065 0.48045504
0.5078553 0.08620858
1.0690873 -0.45957863
-0.2822384 0.79536515
-0.18992352 1.0071297
-0.30851105 0.6323838
-0.48985106 -0.05272095
-0.112165235 -1.2025502
-0.6343776 0.8740463
-0.97740346 0.9715014
-1.2637299 0.6848851
-1.1870348 -0.20320709
-0.65784734 -1.7574068
-2.275478 -0.04044696
-1.5841419 -0.08917504
0.59182155 -0.070345305
1.7027438 -0.23287608
2.2658849 -0.10763591
-2.0428355 0.10209269
-0.9335362 -0.049792744
0.25750664 -0.07547748
1.0987146 0.10696673
1.5473177 -0.16306788
-0.8157582 0.088507146
-0.23004234 0.02865851
0.3001771 -0.13394779
0.6583938 -0.10253158
1.0895797 -0.036603633
-0.093778014 -0.20971416
0.08269198 -0.051816575
0.17656319 0.18494779
0.3352879 -0.020245025
1.0185977 -0.07630297
-0.6558476 -0.12080981
0.4106111 -0.12838727
0.3651244 0.07689702
0.3434926 -0.1401755
0.78885883 -0.047443036
0.9312759 -0.4872008
0.45665312 -0.755767
0.87845147 -0.90513796
1.4286675 -0.6640466
1.9387178 -0.509753
0.0055226237 -0.4808521
-0.11264928 -0.5807188
0.69314396 -0.6151164
1.5066721 -0.5550288
1.5526584 -0.4243716
-0.15990084 -0.40014786
0.10977341 -0.25531605
0.7288155 -0.26900706
1.5179793 -0.35961694
1.5454628 -0.31855944
0.42554915 -0.06904432
0.6133954 0.08449408
1.1112447 -0.04440668
1.4276886 0.05930122
1.3272578 0.0011873574
1.5569048 0.7064937
1.5756388 0.49867254
1.9869299 0.6776411
1.8189707 0.8048061
1.3973557 0.5733196
-4.249913 -0.19441545
-1.9120424 -0.005778725
-0.0061387075 -0.0071499897
0.80639493 0.08352753
1.4316615 -0.13246052
-3.410931 -0.033308238
-1.7743304 0.065881364
-0.18588163 -0.1476445
0.5619047 -0.17577946
1.2757853 -0.20313627
-2.25766 -0.026538868
-1.1736825 0.10845672
-0.47299188 0.12951013
0.38950402 -0.054592907
1.098909 -0.054286536
-2.850165 0.0909873
-1.7250451 0.07470816
-0.7260333 2.0157931e-05
-0.055943523 -0.075895675
0.9642611 -0.0631687
-4.005538 0.1139621
-2.295592 0.13023847
-1.041572 0.07489004
-0.24684854 0.1949782
0.6455168 0.02820571
1.1459881 0.40668908
1.4573389 -0.000711774
1.4954526 -0.744561
1.2473075 -0.5027803
1.0846232 0.20088871
1.2540116 0.96308225
1.9666128 0.92510736
1.9739157 0.5134376
1.2105061 0.25474888
0.7538055 0.4503637
1.2492738 1.6561543
2.14189 1.8223486
1.7544507 1.2207514
0.96942043 0.7662908
0.31504372 0.38526574
1.7381212 1.4918652
2.490894 1.6164081
1.6445026 1.0311278
0.26533163 0.3336429
-0.3193328 -0.15712811
2.0120225 1.4385474
2.0718558 1.0327717
0.8759794 0.056643657
0.04767526 -0.74796945
-0.41645908 -0.96597683
1.2511733 1.1695682
0.5724159 1.2116307
0.37694663 0.67098075
1.2807285 0.061276477
1.8684267 -1.1508046
1.8152616 1.1278331
1.280423 1.0747397
1.101077 0.81522405
1.197118 -0.024527794
1.5331124 -0.95285547
1.7447906 0.8995342
1.6138377 1.0385815
1.4156343 0.71533716
1.0536009 -0.045309864
0.8561865 -1.1234874
1.9363236 0.619687
2.2086453 0.90204847
1.6627563 0.6468797
1.021228 0.33503526
0.60839254 -0.66591007
2.1018016 0.50283337
2.1533952 0.6998083
1.9573407 0.7065805
1.29546 0.5727497
0.57359654 0.04260265
-0.29376534 -0.4851468
0.9012422 -0.20692436
1.1789744 0.19345768
0.710556 1.0645467
0.8737443 1.5191267
0.095544085 0.8372995
1.045074 0.7781821
0.9252817 1.028298
0.471885 1.4177388
0.6031909 1.4664948
-0.2500516 1.3292006
0.14211257 1.3957899
-0.27518043 1.5092078
-1.0673013 1.3398026
-0.845284 0.997704
-0.7930444 1.5843834
-1.1906688 1.6184856
-2.2155006 1.5397934
-2.8370302 1.256475
-2.2175434 0.34014988
-0.9103819 1.5893154
-2.3526044 1.544945
-3.3939815 1.0299425
-3.9634273 0.6678114
-2.9982874 -0.1956785
-3.0668538 -0.10900813
-1.9301875 -0.11298105
0.46062958 -0.016902497
1.1481701 -0.1565643
1.6189759 -0.054204118
-2.693133 -0.034246
-1.3168526 -0.2205075
0.39946663 -0.058389995
0.777253 0.044116203
1.2958935 -0.14663707
-1.7610679 -0.026256435
-0.87182975 -0.10222199
0.015992796 -0.25303757
0.35228586 -0.12922764
0.825145 -0.09234042
-2.3087604 -0.16156028
-1.4618046 0.119986236
-0.49614725 -0.010263173
-0.12511182 -0.04062929
0.5606166 -0.024711546
-3.9921951 0.024872124
-2.422155 -0.037144
-0.9274944 -0.10166565
-0.43651518 0.0026121684
0.110710315 -0.20799841

View File

@@ -1,11 +1,11 @@
10 10
2.4876857 -1.3008373
-0.2729608 -0.09357162
-2.472103 -1.0318826
1.4380744 -0.18906969
0.13707557 -0.31774887
-0.38399124 -1.4002659
-0.10049698 -0.36336994
-0.44721037 3.8660808
-0.24111606 1.2288735
-0.05031827 0.97610044

File diff suppressed because it is too large Load Diff

View File

@@ -1,17 +1,17 @@
16 16
6.674671 -0.10046868
-0.4621555 -0.048594907
-0.35395312 -0.18817224
-6.140842 -0.17443945
-0.6383096 -0.475507
-0.0026992396 -0.014380081
-0.105528705 -0.08149044
-0.12171911 -2.158695
-0.039757866 -4.6233006
-4.064281 -0.6036441
-0.36199543 5.3300047
-0.06976157 -0.009695345
-0.042993866 -0.008206175
0.0015301058 -0.068684034
-0.06826296 -0.023278365
-0.0050806464 3.647335

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,6 @@
4 5
6.171619 5.166837
-1.5262855 -1.2788563
-4.09489 -1.4764651
-2.3815227 -1.0171041
-4.429165

View File

@@ -1,66 +1,82 @@
16 16
4 5
0.70240104 3.3546818e-34
-0.058500186 -5.0533795e-34
-0.23156737 -2.9876767e-35
-0.33127818 -5.747061e-34
-3.6112761e-34 -1.2654221e-33
-3.3890292e-34 3.1982972e-34
9.363116e-34 9.094423e-35
4.0197816e-34 7.818431e-34
-0.2575022 6.1448995e-34
0.69736814 1.2132283e-33
-0.2684227 -8.594385e-34
-0.08991088 4.8569645e-34
-0.3760809 1.8429814e-34
-0.065089576 1.1041889e-33
0.45981047 2.012101e-34
0.008204719 0.00033738822
-4.8556375e-34 -6.27447e-05
4.816393e-34 3.181418e-09
3.872484e-34 5.5260244e-08
5.096778e-34 -4.1039914e-09
1.7445673e-19 -0.29261625
1.2270845e-33 -0.09727536
-2.260416e-25 0.59134495
1.0369542e-20 0.18011163
4.00948e-34 -0.16496071
-5.999333e-34 -4.434109e-34
3.7143163e-34 -2.3553354e-35
-4.228372e-34 1.0642948e-33
-1.0954501e-34 4.470902e-34
-2.7085206e-34 -7.44183e-35
8.016929e-34 7.1034632e-34
9.2079354e-35 6.991907e-34
-3.945864e-34 -1.5644636e-35
1.98814e-34 1.4569e-34
2.3972646e-34 -4.247144e-34
3.942207e-34 -0.10007951
-0.14058167 0.6292724
-0.07198931 -0.11631892
-0.38025984 -0.2893417
0.5981627 -0.060249113
4.3956684e-34 -0.10115793
3.1032594e-34 -0.05707638
3.4351758e-34 -0.021602122
5.5414507e-34 -0.18273582
-1.248324e-34 0.4733028
8.8546844e-35 -0.32697493
6.8084945e-34 0.0043840045
-1.1866068e-34 -0.42484373
-3.865728e-34 0.6746338
1.8786859e-34 0.061171096
3.3450276e-34 0.76072145
-2.8077459e-34 -0.24171914
0.0013890187 -0.18183002
0.026067872 -0.06504542
0.0082543865 -0.23874648
-0.02225164 1.1150656e-34
2.0089658e-34 5.1261775e-34
-6.1273506e-34 -4.443484e-34
-6.228039e-34 -3.415351e-35
-5.0242814e-34 -5.0846646e-34
-4.3343494e-34 6.830828e-13
3.0939117e-34 1.3946587e-21
1.2827092e-34 5.382798e-34
-4.305108e-34 6.7468184e-11
-3.8273462e-34
-8.327467e-34
5.3624216e-35
-1.1396765e-33
-9.036933e-34
-6.1432046e-34
1.0177867e-33
8.3691855e-34
-2.4372232e-34
-1.14444385e-33
3.8171564e-34
0.121070996
-0.054560866
-0.062351264
0.012382605
0.22265062