0 前言
?? 優(yōu)質(zhì)競(jìng)賽項(xiàng)目系列,今天要分享的是
?? **深度學(xué)習(xí)衛(wèi)星遙感圖像檢測(cè)與識(shí)別 **
該項(xiàng)目較為新穎,適合作為競(jìng)賽課題方向,學(xué)長(zhǎng)非常推薦!
??學(xué)長(zhǎng)這里給一個(gè)題目綜合評(píng)分(每項(xiàng)滿分5分)
- 難度系數(shù):3分
- 工作量:3分
- 創(chuàng)新點(diǎn):5分
?? 更多資料, 項(xiàng)目分享:文章來源:http://www.zghlxwxcb.cn/news/detail-835212.html
https://gitee.com/dancheng-senior/postgraduate文章來源地址http://www.zghlxwxcb.cn/news/detail-835212.html
1 課題背景
近年來,世界各國大力發(fā)展航空航天事業(yè),衛(wèi)星圖像的目標(biāo)檢測(cè)在各行各業(yè)的應(yīng)用得到了快速的發(fā)展,特別是軍事偵查、海洋船舶和漁業(yè)管理等領(lǐng)域。由于衛(wèi)星圖像中有價(jià)值的信息極少,衛(wèi)星圖像數(shù)據(jù)規(guī)模巨大,這迫切需要智能輔助工具幫助相關(guān)從業(yè)人員從衛(wèi)星圖像中高效獲取精確直觀的信息。
本文利用深度學(xué)習(xí)技術(shù),基于Yolov5算法框架實(shí)現(xiàn)衛(wèi)星圖像目標(biāo)檢測(cè)問題。
2 實(shí)現(xiàn)效果
實(shí)現(xiàn)效果如下:可以看出對(duì)船只、飛機(jī)等識(shí)別效果還是很好的。
3 Yolov5算法
簡(jiǎn)介
下圖所示為 YOLOv5 的網(wǎng)絡(luò)結(jié)構(gòu)圖,分為輸入端,Backbone,Neck 和 Prediction 四個(gè)部分。其中,
輸入端包括 Mosaic 數(shù)據(jù)增強(qiáng)、自適應(yīng)圖片縮放、自適應(yīng)錨框計(jì)算,Backbone 包括 Focus 結(jié)構(gòu)、CSP
結(jié) 構(gòu),Neck 包 括 FPN+PAN 結(jié) 構(gòu),Prediction 包 括GIOU_Loss 結(jié)構(gòu)。
相關(guān)代碼
?
class Yolo(object):
def __init__(self, weights_file, verbose=True):
self.verbose = verbose
# detection params
self.S = 7 # cell size
self.B = 2 # boxes_per_cell
self.classes = ["aeroplane", "bicycle", "bird", "boat", "bottle",
"bus", "car", "cat", "chair", "cow", "diningtable",
"dog", "horse", "motorbike", "person", "pottedplant",
"sheep", "sofa", "train","tvmonitor"]
self.C = len(self.classes) # number of classes
# offset for box center (top left point of each cell)
self.x_offset = np.transpose(np.reshape(np.array([np.arange(self.S)]*self.S*self.B),
[self.B, self.S, self.S]), [1, 2, 0])
self.y_offset = np.transpose(self.x_offset, [1, 0, 2])
self.threshold = 0.2 # confidence scores threhold
self.iou_threshold = 0.4
# the maximum number of boxes to be selected by non max suppression
self.max_output_size = 10
self.sess = tf.Session()
self._build_net()
self._build_detector()
self._load_weights(weights_file)
4 數(shù)據(jù)處理和訓(xùn)練
數(shù)據(jù)集
本項(xiàng)目使用 DOTA 數(shù)據(jù)集,原數(shù)據(jù)集中待檢測(cè)的目標(biāo)如下
原數(shù)據(jù)集中的標(biāo)簽如下
圖像分割和尺寸調(diào)整
YOLO 模型的圖像輸入尺寸是固定的,由于原數(shù)據(jù)集中的圖像尺寸不一,我們將原數(shù)據(jù)集中的圖像按目標(biāo)分布的位置分割成一個(gè)個(gè)包含目標(biāo)的子圖,并將每個(gè)子圖尺寸調(diào)整為
1024×1024。分割前后的圖像如所示。
分割前
分割后
模型訓(xùn)練
在 yolov5/ 目錄,運(yùn)行 train.py 文件開始訓(xùn)練:
?
python train.py --weight weights/yolov5s.pt --batch 16 --epochs 100 --cache
其中的參數(shù)說明:
- weight:使用的預(yù)訓(xùn)練權(quán)重,這里示范使用的是 yolov5s 模型的預(yù)訓(xùn)練權(quán)重
- batch:mini-batch 的大小,這里使用 16
- epochs:訓(xùn)練的迭代次數(shù),這里我們訓(xùn)練 100 個(gè) epoch
- cache:使用數(shù)據(jù)緩存,加速訓(xùn)練進(jìn)程
相關(guān)代碼
?
#部分代碼
def train(hyp, opt, device, tb_writer=None):
logger.info(f'Hyperparameters {hyp}')
log_dir = Path(tb_writer.log_dir) if tb_writer else Path(opt.logdir) / 'evolve' # logging directory
wdir = log_dir / 'weights' # weights directory
os.makedirs(wdir, exist_ok=True)
last = wdir / 'last.pt'
best = wdir / 'best.pt'
results_file = str(log_dir / 'results.txt')
epochs, batch_size, total_batch_size, weights, rank = \
opt.epochs, opt.batch_size, opt.total_batch_size, opt.weights, opt.global_rank
# Save run settings
with open(log_dir / 'hyp.yaml', 'w') as f:
yaml.dump(hyp, f, sort_keys=False)
with open(log_dir / 'opt.yaml', 'w') as f:
yaml.dump(vars(opt), f, sort_keys=False)
# Configure
cuda = device.type != 'cpu'
init_seeds(2 + rank)
with open(opt.data) as f:
data_dict = yaml.load(f, Loader=yaml.FullLoader) # data dict
with torch_distributed_zero_first(rank):
check_dataset(data_dict) # check
train_path = data_dict['train']
test_path = data_dict['val']
nc, names = (1, ['item']) if opt.single_cls else (int(data_dict['nc']), data_dict['names']) # number classes, names
assert len(names) == nc, '%g names found for nc=%g dataset in %s' % (len(names), nc, opt.data) # check
# Model
pretrained = weights.endswith('.pt')
if pretrained:
with torch_distributed_zero_first(rank):
attempt_download(weights) # download if not found locally
ckpt = torch.load(weights, map_location=device) # load checkpoint
if 'anchors' in hyp and hyp['anchors']:
ckpt['model'].yaml['anchors'] = round(hyp['anchors']) # force autoanchor
model = Model(opt.cfg or ckpt['model'].yaml, ch=3, nc=nc).to(device) # create
exclude = ['anchor'] if opt.cfg else [] # exclude keys
state_dict = ckpt['model'].float().state_dict() # to FP32
state_dict = intersect_dicts(state_dict, model.state_dict(), exclude=exclude) # intersect
model.load_state_dict(state_dict, strict=False) # load
logger.info('Transferred %g/%g items from %s' % (len(state_dict), len(model.state_dict()), weights)) # report
else:
model = Model(opt.cfg, ch=3, nc=nc).to(device) # create
# Freeze
freeze = ['', ] # parameter names to freeze (full or partial)
if any(freeze):
for k, v in model.named_parameters():
if any(x in k for x in freeze):
print('freezing %s' % k)
v.requires_grad = False
# Optimizer
nbs = 64 # nominal batch size
accumulate = max(round(nbs / total_batch_size), 1) # accumulate loss before optimizing
hyp['weight_decay'] *= total_batch_size * accumulate / nbs # scale weight_decay
pg0, pg1, pg2 = [], [], [] # optimizer parameter groups
for k, v in model.named_parameters():
v.requires_grad = True
if '.bias' in k:
pg2.append(v) # biases
elif '.weight' in k and '.bn' not in k:
pg1.append(v) # apply weight decay
else:
pg0.append(v) # all else
?
訓(xùn)練開始時(shí)的日志信息
5 最后
?? 更多資料, 項(xiàng)目分享:
https://gitee.com/dancheng-senior/postgraduate
到了這里,關(guān)于計(jì)算機(jī)設(shè)計(jì)大賽 深度學(xué)習(xí)衛(wèi)星遙感圖像檢測(cè)與識(shí)別 -opencv python 目標(biāo)檢測(cè)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!