1. 程式人生 > 其它 >目標檢測---Faster Rcnn原理

目標檢測---Faster Rcnn原理

目錄

01 初始資料庫

02 庫相關操作

# 增
create database db1;
create database db2 charset='gbk';

# 查
show databases;   # 查所有
show create database db1; # 查單個
# 改
alter database db2 charset='utf8';

# 刪
drop database db2;

# 修改表名
alter table 表名 rename 新表名;

# 增加欄位
alter table 表名 add 欄位名 欄位型別(寬度) 約束條件;
alter table 表名 add 欄位名 欄位型別(寬度) 約束條件 first;  # 增加到最前面
alter table 表名 add 欄位名 欄位型別(寬度) 約束條件 after 欄位名; # 增加到某欄位後面
示例:
alter table xx add gender anum('male','female',others'') default 'male';
alter table xx add age int default 18 first;
alter table xx add qq int default 123456 after gender;

# 刪除欄位
alter table 表名 drop 欄位名;
示例:
alter table xx drop qq;

# 修改欄位
alter table 表名 modify 欄位名 欄位型別(寬度) 約束條件;
alter table 表名 change 舊欄位名  新欄位名 欄位型別(寬度) 約束條件;
示例:
alter table xx modify age bigint default 18;
alter table xx change age age int default 19;

# 複製表
create table 表名 select * from 舊錶;  不能複製主鍵 外來鍵……

create table new_dep2 select * from dep where id>3;

03 表相關操作

# 檢視當前所在庫的名字
select database();

# 切換庫
use text;

# 增
create table t1(id int,name,char(8),gender int);

# 查
show tables;  # 檢視當前庫下面所有的表名
show create table t1;
describe t1;  # 簡寫 desc t1;

# 改
alter table t1 modify name char(16);

# 刪
drop table t1;

04 資料相關操作

# 一定先有庫 有表 最好才能插入資料

# 增
insert into t1 values(1,'fx');
insert into t1 values(2,'xx'),(3,'xy'),(4,'pp');

# 查
select * from t1;
select name from t1;

# 改
update t1 set name='ll' where id = 4;

# 刪
delete from t1;

05 儲存引擎

  • innodb
    是mysql 5.5及之後版本預設儲存引擎
    儲存資料更加的安全
    建立表會生產兩個檔案:
    表結構檔案
    表資料檔案

  • myisam
    是mysql5.5之前版本預設儲存引擎
    儲存速度比innodb要快 但是我們更注重的是資料安全
    建立表會生產三個檔案:
    表結構檔案
    表資料檔案
    表索引檔案

  • memory
    記憶體引擎(資料存放在記憶體)斷電資料丟失
    建立表會建立一個檔案:
    表結構檔案

  • blackhole
    無論存什麼立馬消失
    建立表會建立一個檔案:
    表結構檔案

# 檢視所有的儲存引擎
show engines;

# 不同的儲存引擎在儲存表的時候 異同點
create table t1(id int) engine=innodb;
create table t2(id int) engine=myisam;
create table t3(id int) engine=blackhole;
create table t4(id int) engine=memory;

# 存資料
insert into t1 values(1);
insert into t2 values(1);
insert into t3 values(1);
insert into t4 values(1);

06 建立表的完整語法

# 語法
create table 表名(
	欄位名	欄位型別(寬度)	約束條件,
	欄位名	欄位型別(寬度)	約束條件,
	欄位名	欄位型別(寬度)	約束條件
)
# 注意
1) 在通一張表中表欄位不能重複
2)寬度和約束條件是可選的而欄位名和欄位型別是必須的
	約束條件寫的話  也支援寫多個
	欄位名1 型別(寬度) 約束條件1 約束條件2.......,
	create table t5(id); 報錯
3)最後一行不能有逗號
create table t6(
	id int,
	name char(8),
);   # 報錯

07 嚴格模式

# 如何檢視嚴格模式
show variables like "%mode";

模糊匹配/查詢
	關鍵字 like
	%:匹配任意多個字元
	_:匹配任意單個字元

# 修改嚴格模式
	set session  只在當前視窗有效
	set global   全域性有效

	set global sql_mode = 'STRICT_TRANS_TABLES';

    修改完之後 重新進入服務端即可

08 基本資料型別

整型

  • 分類
    TINYINT、SMALLINT、EDUIMINT、INT、BIGINT
  • 作用
    儲存年齡、等級、id、號碼等等
以tinyint
	是否有符號
		預設情況下是帶符號的
	超出會如何
		超出現在只存最大可接收值

create table t9(id tinyint);
insert into t9 values(-129),(256);

# 約束條件之unsigned 無符號
create table t10(id tinyint unsigned);


create table t11(id int);
# int預設也是帶符號的  
# 整型預設情況下都是帶有符號的

# 針對整型 括號內的寬度到底是幹嘛的
create table t12(id int(8));
insert into t12 values(123456789);

"""
特例:只有整型括號裡面的數字不是表示限制位數
id int(8)
	如果數字沒有超出8位 那麼預設用空格填充至8位
	如果數字超出了8位 那麼有幾位就存幾位(但是還是要遵守最大範圍)
"""
create table t13(id int(8) unsigned zerofill);
# 用0填充至8位

# 總結
針對整型欄位 括號內無需指定寬度 因為它預設的寬度以及足夠顯示所有的資料了

浮點型

  • 分類
    float、double、decimal
  • 作用
    身高、體重、薪資
float(255,30) # 總共255位,小數部分佔30位
double(255,30) # 總共255位,小數部分佔30位
decimal(65,30) # 總共65位 小數部分佔30位

# 精確度驗證
create table t1(id float(255,30));
create table t2(id double(255,30));
create table t3(id decimal(65,30));

insert into t1 values(1.111111111111111111111111111111);
insert into t2 values(1.111111111111111111111111111111);
insert into t3 values(1.111111111111111111111111111111);

float < double < decimal

字元型別

  • 分類
char
	定長
	char(4)  資料超過四個字元直接報錯,不夠四個字元空格補全。
varchar 
	變長
	varchar(4) 資料超過四個字元直接報錯,不夠有幾個存幾個

create table t9(name char(4));
create table t10(name varchar(4));

insert into t9 values('a');
insert into t10 values('a');

# 統計欄位長度
select char_length(name) from t9;
select char_length(name) from t10;

"""
首先可以肯定的是 char硬碟上存的絕對是真正的資料 帶有空格的
但是在顯示的時候MySQL會自動將多餘的空格剔除
"""
# 再次修改sql_mode 讓MySQL不要做自動剔除操作
set global sql_mode = 'STRICT_TRANS_TABLES,PAD_CHAR_TO_FULL_LENGTH';

# 再次統計欄位長度
select char_length(name) from t9;
+-------------------+
| char_length(name) |
+-------------------+
|                 4 |
+-------------------+
1 row in set (0.00 sec)

select char_length(name) from t10;
+-------------------+
| char_length(name) |
+-------------------+
|                 1 |
+-------------------+
1 row in set (0.00 sec)

char與varchar對比

char
	優點:存取都很簡單,直接按照固定的字元存取資料即可,存按照五個存,取按照五個取
	缺點:浪費空間


varchar
	優點:節省空間
	缺點:存取比較麻煩,存的時候需要製作抱頭,取的時候也需要先讀取抱頭,之後才能讀取真實資料

時間型別

  • 分類
    date:2022-3-29
    datetime: 2022-3-29 11:11:11
    time:11:11:11
    year:2022
create table student(id int,name varchar(16),born_year year,birth date,study_time time,reg_time datetime);

insert into student values(1,'xx','2022','2022-03-29','11:11:11','2022-03-29 11:11:11');
Query OK, 1 row affected (0.00 sec)

select * from student;
+------+------+-----------+------------+------------+---------------------+
| id   | name | born_year | birth      | study_time | reg_time            |
+------+------+-----------+------------+------------+---------------------+
|    1 | xx   |      2022 | 2022-03-29 | 11:11:11   | 2022-03-29 11:11:11 |
+------+------+-----------+------------+------------+---------------------+
1 row in set (0.00 sec)

列舉與集合型別

  • 分類
列舉(enum)	多選一
集合(set)	多選多
  • 具體使用
create table teacher(id int,name char(8),gender enum('male','female','others'),hobby set('read','xixi','hehe'));

insert into teacher values(1,'fx','male','read');

insert into teacher values(2,'xx','female','xixi,hehe');

insert into teacher values(3,'ll','others','xx'); #報錯

09 約束條件

  • default 預設值
# 插入資料的時候可以指定欄位
create table t2(id int,name char(8),gender enum('male','female','others'));

insert into t2(id,name) values(1,'fx');
insert into t2 values(2,'xx','female');

  • unique唯一
# 單例唯一
create table t3(id int unique,name char(8));

insert into t3 values(1,'fx');
insert into t3 values(1,'xx') # 報錯

# 聯合唯一
"""
ip和port
單個都可以重複 但是載入一起必須是唯一的
"""
create table t4(id int,ip char(16),port int,unique(ip,port));

insert into t4 values(1,'127.0.0.1',8080);
insert into t4 values(2,'127.0.0.1',8081);
insert into t4 values(3,'127.0.0.2',8080);
insert into t4 values(4,'127.0.0.1',8080);  報錯
  • primary key主鍵
    """
    1.單單從約束效果上來看primary key等價於not null + unique
    非空且唯一!!!
    """
create table t5(id int primary key);
insert into t5 values(null) #報錯
insert into t5 values(1),(2);
insert into t5 values(1),(2);  #報錯

"""
2. 它除了有約束效果之外 它還是innodb儲存引擎組織資料的依據
innodb儲存引擎在建立表的時候必須要有primary key
因為它類似於書的目錄 能夠幫助提升查詢效率並且也是建表的依據
"""

# 1 一張表有且只要一個主鍵 如果你沒有設定主鍵 那麼會從上往下搜尋直到遇到一個非空且唯一的欄位將它自動升級為主鍵
create table t5(
id int,
name char(8),
age int not null unique,
addr int not null unique
);

desc t5;
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id    | int(11) | NO   | PRI | NULL    |       |
+-------+---------+------+-----+---------+-------+
1 row in set (0.00 sec)


# 2 如果表中沒有主鍵也沒有其他任何的非空且唯一欄位  那麼innodb會採用自己內部提供的一個隱藏欄位作為主鍵,隱藏意味著無法使用它 就沒發提升查詢速度

# 3 一張表中通常都應該有一個主鍵欄位 並且通常將id、uid、sid欄位作為主鍵
# 單欄位主鍵
create table t6(
id int primary key,
name char(16)
);

# 聯合主鍵(多個欄位聯合起來作為表的主鍵 本質還是一個主鍵)
create table t7(
ip char(16),
port int,
primary key(ip,port)
);

"""
以後建立表的時候一定要加primary key
"""
  • auto_increment 自增
create table t9(
id int primary key auto_increment,
name char(16)
);
insert into t9(name) values('fx'),('xx'),('xy'));

 select * from t9;
+----+------+
| id | name |
+----+------+
|  1 | fx   |
|  2 | xx   |
|  3 | xy   |
+----+------+
3 rows in set (0.00 sec)


desc t9;
+-------+----------+------+-----+---------+----------------+
| Field | Type     | Null | Key | Default | Extra          |
+-------+----------+------+-----+---------+----------------+
| id    | int(11)  | NO   | PRI | NULL    | auto_increment |
| name  | char(16) | YES  |     | NULL    |                |
+-------+----------+------+-----+---------+----------------+
2 rows in set (0.00 sec)

# 注意 auto_increment通常是加在主鍵上 不能給普通欄位加
create table t10(id int primary key auto_increment,name char(16) cid int auto_increment);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'cid int auto_increment)' at line 1

"""
結論:以後建立表的id(資料的唯一標識id、uid、cid)欄位的時候
id int primary key auto_increment
"""

10 表與表之間建關係

"""
定義一張員工表 表中有很多欄位
id name gender dep_name dep_desc
"""
# 1 該表的組織架構不是很清晰
# 2 浪費磁碟空間
# 3 資料的擴充套件性極差

# 如何優化?
"""
上述問題就類似於你將所有的程式碼都寫在一個py檔案,冗餘性差,將員工表拆分 員工表和部門表
"""
外來鍵
"""
外來鍵就是用來幫助我們建立表與表之間關係的
foreign key
"""
表關係
表與表之間有四種關係:
	1、一對多關係(一對多、多對一都叫一對多)
	2、多對多關係
	3、一對一關係
	4、沒有關係
一對多關係

"""
判斷表與表關係的時候 前期不熟悉的情況下  換位思考 分別站在兩張表的角度考慮

員工表與部門表為例
	先站在員工表
		思考一個員工是否能對應多個部門(不能)
	站在部門表
		一個部門是否能對應多個員工(能)
	員工表和部門表是單向的一對多
	所以表關係是一對多
"""
foreign key
	1 一對多關係   外來鍵欄位建在多的一方
	2 在建立表的時候 一定先建被關聯表
	3 在錄入資料的時候 也必須先錄入被關聯表

# sql語句建立關係
create table dep(
id int primary key auto_increment,
dep_name char(8),
dep_desc char(8),
);

create table users(
id int primary key auto_increment,
name char(8),
gender  enum('male','female','others')
dep_id int,
foreign key(dep_id) references dep(id)
);
desc dep;
+----------+---------+------+-----+---------+----------------+
| Field    | Type    | Null | Key | Default | Extra          |
+----------+---------+------+-----+---------+----------------+
| id       | int(11) | NO   | PRI | NULL    | auto_increment |
| dep_name | char(8) | YES  |     | NULL    |                |
| dep_desc | char(8) | YES  |     | NULL    |                |
+----------+---------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

desc users;
+--------+--------------------------------+------+-----+---------+----------------+
| Field  | Type                           | Null | Key | Default | Extra          |
+--------+--------------------------------+------+-----+---------+----------------+
| id     | int(11)                        | NO   | PRI | NULL    | auto_increment |
| name   | char(8)                        | YES  |     | NULL    |                |
| gender | enum('male','female','others') | YES  |     | NULL    |                |
| dep_id | int(11)                        | YES  | MUL | NULL    |                |
+--------+--------------------------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
# 插入資料
insert into dep(dep_name,dep_desc) values('技術部','修電腦的'),('財務部','收錢的'),('人事部','裁員的');

insert into users(name,gender,dep_id) values('xx','male',1),('yy','male',1),('zz','male',2),('vv','male',3),('ee','male',3),('jj','female',1);

# 報錯(插入資料dep_id在dep裡不存在報錯)
insert into users(name,gender,dep_id) values('kk','female',4);
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`text02`.`users`, CONSTRAINT `users_ibfk_1` FOREIGN KEY (`dep_id`) REFERENCES `dep` (`id`))


# 修改dep表裡面的id欄位
update dep set id=200 where id=2;  #不行
# 刪除dep表裡面的資料
delete from dep;

# 1 先刪除部門對應的員工資料 之後再刪除部門
	操作太繁瑣

# 2 真正做到資料直接有關係
	更新就同步更新
	刪除就同步刪除

"""
級聯更新  >>>  同步更新
級聯刪除  >>>  同步刪除
"""
create table dep(
id int primary key auto_increment,
dep_name char(8),
dep_desc char(8)
);

create table users(
id int primary key auto_increment,
name char(8),
gender enum('male','female','others'),
dep_id int,
foreign key(dep_id) references dep(id)
on update cascade
on delete cascade
);

# 更新部門資料,員工也跟著更新
update dep set id=200 where id=3;

select * fromm dep;
+-----+-----------+-----------+
| id  | dep_name  | dep_desc  |
+-----+-----------+-----------+
|   1 | 技術部    | 擼碼的    |
|   2 | 財務部    | 收錢的    |
| 200 | 人事部    | 裁員的    |
+-----+-----------+-----------+

select * from user;
+----+------+--------+--------+
| id | name | gender | dep_id |
+----+------+--------+--------+
|  1 | xx   | male   |      1 |
|  2 | yy   | male   |      1 |
|  3 | zz   | male   |      2 |
|  4 | vv   | male   |    200 |
|  5 | ee   | male   |    200 |
|  6 | jj   | female |      1 |
+----+------+--------+--------+


# 刪除部門表資料 該部門下員工也被刪除
delete from dep where id = 200;
Query OK, 1 row affected (0.00 sec)

select * from dep;
+----+-----------+-----------+
| id | dep_name  | dep_desc  |
+----+-----------+-----------+
|  1 | 技術部    | 擼碼的    |
|  2 | 財務部    | 收錢的    |
+----+-----------+-----------+
2 rows in set (0.00 sec)

select * from user;
+----+------+--------+--------+
| id | name | gender | dep_id |
+----+------+--------+--------+
|  1 | xx   | male   |      1 |
|  2 | yy   | male   |      1 |
|  3 | zz   | male   |      2 |
|  6 | jj   | female |      1 |
+----+------+--------+--------+
4 rows in set (0.00 sec)
多對多關係
"""
圖書表和作者表
"""
create table book(
id int primary key auto_increment,
title vachar(32),
price int,
author_id int,
foreign key(author_id) references book(id)
on update cascade
on delete cascade
);

create author(
id int primary key auto_increment,
name varchar(32),
age int,
book_id int,
foreign key(book_id) references book(id)
on update cascade
on delete cascade
);

"""
按照上述的方式建立 一個都不能建立成功
其實我們只想記錄書籍和作者的關係
針對多對多欄位表關係  不能在兩張原有的表中建立外來鍵
需要單獨在開設一張表 專門用來儲存兩張表資料之間的關係
"""
create table book(
id int primary key auto_increment,
title varchar(32),
price int
);

create table author(
id int primary key auto_increment,
name varchar(32),
age int
);

  create table book2author(
  id int primary key auto_increment,
  author_id int,
  book_id int,
  foreign key(author_id) references author(id)
  on update cascade
  on delete cascade,
  foreign key(book_id) references book(id)
  on update cascade
  on delete cascade
  );

desc book2author;
+-----------+---------+------+-----+---------+----------------+
| Field     | Type    | Null | Key | Default | Extra          |
+-----------+---------+------+-----+---------+----------------+
| id        | int(11) | NO   | PRI | NULL    | auto_increment |
| author_id | int(11) | YES  | MUL | NULL    |                |
| book_id   | int(11) | YES  | MUL | NULL    |                |
+-----------+---------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
一對一關係
"""
id name age addr phone habby email……
如果一個表的欄位特別多 每次查詢又不是所有的欄位都能用得到

將表一分為二
    使用者表
        使用者表
          id name age
        使用者詳情表
          id addr phone hobby email……
    站在使用者表
        一個使用者能否對應多個使用者詳情        不能
    站在詳情表
        一個使用者詳情是否屬於多個使用者         不能
    結論: 單向的一對多都不成立 那麼這個時候兩者之間的表關係就是一對一 或者沒有關係
"""
一對一  外來鍵欄位建在任意一方都可以  但是推薦建在查詢頻率比較高的表中
create table authordetail(
id int primary key auto_increment,
phone bigint,
addr varchar(64)
);

create table author(
id int primary key auto_increment,
name varchar(32),
age int,
authordetail_id int unique,
foreign key(authordetail_id) references authordetail(id)
on update cascade
on delete cascade
);

insert into authordetail(phone,addr) values(13164151001,'湖北武漢'),(13164654135,'湖北武漢');

insert into author(name,age,authordateil_id) values('fx',18,1);

insert into author(name,age,authordateil_id) values('xx',18,1);  # 報錯

insert into author(name,age,authordateil_id) values('xx',18,2);

返回頂部