kmeans++聚类生成anchors

article/2025/11/5 16:29:02

kmeans++聚类生成anchors

说明

使用yolo系列通常需要通过kmeans聚类算法生成anchors,
但kmeans算法本身具有一定的局限性,聚类结果容易受初始值选取影响。
因此通过改进原kmeans_for_anchors.py实现 kmeans++聚类生成anchors。

具体实现如下:

import glob
import xml.etree.ElementTree as ET
from tqdm import tqdm
import numpy as npdef cas_iou(box, cluster):x = np.minimum(cluster[:, 0], box[0])y = np.minimum(cluster[:, 1], box[1])intersection = x * yarea1 = box[0] * box[1]area2 = cluster[:, 0] * cluster[:, 1]iou = intersection / (area1 + area2 - intersection)return ioudef avg_iou(box, cluster):return np.mean([np.max(cas_iou(box[i], cluster)) for i in range(box.shape[0])])def bboxesOverRation(bboxesA, bboxesB):"""功能等同于matlab的函数bboxesOverRationbboxesA:M*4 array,形如[x,y,w,h]排布bboxesB: N*4 array,形如[x,y,w,h]排布"""bboxesA = np.array(bboxesA.astype('float'))bboxesB = np.array(bboxesB.astype('float'))M = bboxesA.shape[0]N = bboxesB.shape[0]areasA = bboxesA[:, 2] * bboxesA[:, 3]areasB = bboxesB[:, 2] * bboxesB[:, 3]xA = bboxesA[:, 0] + bboxesA[:, 2]yA = bboxesA[:, 1] + bboxesA[:, 3]xyA = np.stack([xA, yA]).transpose()xyxyA = np.concatenate((bboxesA[:, :2], xyA), axis=1)xB = bboxesB[:, 0] + bboxesB[:, 2]yB = bboxesB[:, 1] + bboxesB[:, 3]xyB = np.stack([xB, yB]).transpose()xyxyB = np.concatenate((bboxesB[:, :2], xyB), axis=1)iouRatio = np.zeros((M, N))for i in range(M):for j in range(N):x1 = max(xyxyA[i, 0], xyxyB[j, 0]);x2 = min(xyxyA[i, 2], xyxyB[j, 2]);y1 = max(xyxyA[i, 1], xyxyB[j, 1]);y2 = min(xyxyA[i, 3], xyxyB[j, 3]);Intersection = max(0, (x2 - x1)) * max(0, (y2 - y1));Union = areasA[i] + areasB[j] - Intersection;iouRatio[i, j] = Intersection / Union;return iouRatiodef load_data(path):data = []# 对于每一个xml都寻找boxfor xml_file in tqdm(glob.glob('{}/*xml'.format(path))):tree = ET.parse(xml_file)height = int(tree.findtext('./size/height'))width = int(tree.findtext('./size/width'))if height <= 0 or width <= 0:continue# 对于每一个目标都获得它的宽高for obj in tree.iter('object'):xmin = int(float(obj.findtext('bndbox/xmin'))) / widthymin = int(float(obj.findtext('bndbox/ymin'))) / heightxmax = int(float(obj.findtext('bndbox/xmax'))) / widthymax = int(float(obj.findtext('bndbox/ymax'))) / heightxmin = np.float64(xmin)ymin = np.float64(ymin)xmax = np.float64(xmax)ymax = np.float64(ymax)# 得到宽高x = xmin + 0.5 * (xmax - xmin)y = ymin + 0.5 * (ymax - ymin)data.append([x, y, xmax - xmin, ymax - ymin])return np.array(data)def estimateAnchorBoxes(trainingData, numAnchors=9):'''功能:kmeans++算法估计anchor,类似于matlab函数estimateAnchorBoxes,当trainingData数据量较大时候,自写的kmeans迭代循环效率较低,matlab的estimateAnchorBoxes得出anchors较快,但meanIOU较低,然后乘以实际box的ratio即可。此算法由于优化是局部,易陷入局部最优解,结果不一致属正常cuixingxing150@gmail.comExample:import scipy.io as scipodata = scipo.loadmat(r'D:\Matlab_files\trainingData.mat')trainingData = data['temp']meanIoUList = []for numAnchor in np.arange(1,16):anchorBoxes,meanIoU = estimateAnchorBoxes(trainingData,numAnchors=numAnchor)meanIoUList.append(meanIoU)plt.plot(np.arange(1,16),meanIoUList,'ro-')plt.ylabel("Mean IoU")plt.xlabel("Number of Anchors")plt.title("Number of Anchors vs. Mean IoU")Parameters----------trainingData : numpy 类型形如[x,y,w,h]排布,M*4大小二维矩阵numAnchors : int, optional估计的anchors数量. The default is 9.Returns-------anchorBoxes : numpy类型形如[w,h]排布,N*2大小矩阵.meanIoU : scalar 标量DESCRIPTION.'''numsObver = trainingData.shape[0]xyArray = np.zeros((numsObver, 2))trainingData[:, 0:2] = xyArrayassert (numsObver >= numAnchors)# kmeans++# initcentroids = []  # 初始化中心,kmeans++centroid_index = np.random.choice(numsObver, 1)centroids.append(trainingData[centroid_index])while len(centroids) < numAnchors:minDistList = []for box in trainingData:box = box.reshape((-1, 4))minDist = 1for centroid in centroids:centroid = centroid.reshape((-1, 4))ratio = (1 - bboxesOverRation(box, centroid)).item()if ratio < minDist:minDist = ratiominDistList.append(minDist)sumDist = np.sum(minDistList)prob = minDistList / sumDistidx = np.random.choice(numsObver, 1, replace=True, p=prob)centroids.append(trainingData[idx])# kmeans 迭代聚类maxIterTimes = 100iter_times = 0while True:minDistList = []minDistList_ind = []for box in trainingData:box = box.reshape((-1, 4))minDist = 1box_belong = 0for i, centroid in enumerate(centroids):centroid = centroid.reshape((-1, 4))ratio = (1 - bboxesOverRation(box, centroid)).item()if ratio < minDist:minDist = ratiobox_belong = iminDistList.append(minDist)minDistList_ind.append(box_belong)centroids_avg = []for _ in range(numAnchors):centroids_avg.append([])for i, anchor_id in enumerate(minDistList_ind):centroids_avg[anchor_id].append(trainingData[i])err = 0for i in range(numAnchors):if len(centroids_avg[i]):temp = np.mean(centroids_avg[i], axis=0)err += np.sqrt(np.sum(np.power(temp - centroids[i], 2)))centroids[i] = np.mean(centroids_avg[i], axis=0)iter_times += 1if iter_times > maxIterTimes or err == 0:breakanchorBoxes = np.array([x[2:] for x in centroids])meanIoU = 1 - np.mean(minDistList)print('acc:{:.2f}%'.format(avg_iou(trainingData[:, 2:], anchorBoxes) * 100))return anchorBoxes, meanIoUif __name__ == "__main__":np.random.seed(0)#  载入数据集,可以使用VOC的xmlpath = 'VOCdevkit/VOC2007/Annotations'# 生成的anchors的txt文件保存路径anchorsPath = 'yolo_anchors++.txt'# 生成的anchors数量anchors_num = 9# 输入的图片尺寸input_shape = [416, 416]print('Load xmls.')data = load_data(path)print('Load xmls done.')#   使用k聚类算法print('K-means++ boxes.')anchors, _= estimateAnchorBoxes(data, numAnchors=anchors_num)print('K-means boxes done.')anchors = anchors *  np.array([input_shape[1], input_shape[0]])# 排序cluster = anchors[np.argsort(anchors[:, 0])]print("聚类结果")print(cluster)# 保存结果 生成yolo_anchors++.txt文件f = open(anchorsPath, 'w')row = np.shape(cluster)[0]for i in range(row):if i == 0:x_y = "%d,%d" % (cluster[i][0], cluster[i][1])else:x_y = ", %d,%d" % (cluster[i][0], cluster[i][1])f.write(x_y)f.close()

使用voc数据集运行结果如下:

代码运行时间比较长,耐心等待即可!

在这里插入图片描述

参考

1.YOLOV4生成锚框kmeans_for_anchors.py

#-------------------------------------------------------------------------------------------------------#
#   kmeans虽然会对数据集中的框进行聚类,但是很多数据集由于框的大小相近,聚类出来的9个框相差不大,
#   这样的框反而不利于模型的训练。因为不同的特征层适合不同大小的先验框,shape越小的特征层适合越大的先验框
#   原始网络的先验框已经按大中小比例分配好了,不进行聚类也会有非常好的效果。
#-------------------------------------------------------------------------------------------------------#
import glob
import xml.etree.ElementTree as ETimport matplotlib.pyplot as plt
import numpy as np
from tqdm import tqdmdef cas_iou(box, cluster):x = np.minimum(cluster[:, 0], box[0])y = np.minimum(cluster[:, 1], box[1])intersection = x * yarea1 = box[0] * box[1]area2 = cluster[:,0] * cluster[:,1]iou = intersection / (area1 + area2 - intersection)return ioudef avg_iou(box, cluster):return np.mean([np.max(cas_iou(box[i], cluster)) for i in range(box.shape[0])])def kmeans(box, k):#-------------------------------------------------------------##   取出一共有多少框#-------------------------------------------------------------#row = box.shape[0]#-------------------------------------------------------------##   每个框各个点的位置#-------------------------------------------------------------#distance = np.empty((row, k))#-------------------------------------------------------------##   最后的聚类位置#-------------------------------------------------------------#last_clu = np.zeros((row, ))np.random.seed()#-------------------------------------------------------------##   随机选5个当聚类中心#-------------------------------------------------------------#cluster = box[np.random.choice(row, k, replace = False)]iter = 0while True:#-------------------------------------------------------------##   计算当前框和先验框的宽高比例#-------------------------------------------------------------#for i in range(row):distance[i] = 1 - cas_iou(box[i], cluster)#-------------------------------------------------------------##   取出最小点#-------------------------------------------------------------#near = np.argmin(distance, axis=1)if (last_clu == near).all():break#-------------------------------------------------------------##   求每一个类的中位点#-------------------------------------------------------------#for j in range(k):cluster[j] = np.median(box[near == j],axis=0)last_clu = nearif iter % 5 == 0:print('iter: {:d}. avg_iou:{:.2f}'.format(iter, avg_iou(box, cluster)))iter += 1return cluster, neardef load_data(path):data = []#-------------------------------------------------------------##   对于每一个xml都寻找box#-------------------------------------------------------------#for xml_file in tqdm(glob.glob('{}/*xml'.format(path))):tree    = ET.parse(xml_file)height  = int(tree.findtext('./size/height'))width   = int(tree.findtext('./size/width'))if height<=0 or width<=0:continue#-------------------------------------------------------------##   对于每一个目标都获得它的宽高#-------------------------------------------------------------#for obj in tree.iter('object'):xmin = int(float(obj.findtext('bndbox/xmin'))) / widthymin = int(float(obj.findtext('bndbox/ymin'))) / heightxmax = int(float(obj.findtext('bndbox/xmax'))) / widthymax = int(float(obj.findtext('bndbox/ymax'))) / heightxmin = np.float64(xmin)ymin = np.float64(ymin)xmax = np.float64(xmax)ymax = np.float64(ymax)# 得到宽高data.append([xmax - xmin, ymax - ymin])return np.array(data)if __name__ == '__main__':np.random.seed(0)#-------------------------------------------------------------##   运行该程序会计算'./VOCdevkit/VOC2007/Annotations'的xml#   会生成yolo_anchors.txt#-------------------------------------------------------------#input_shape = [416, 416]anchors_num = 9#-------------------------------------------------------------##   载入数据集,可以使用VOC的xml#-------------------------------------------------------------#path        = 'C:\\Users\\52xj\\Desktop\\mobilenet-yolov4-pytorch-main\\mobilenet-yolov4-pytorch-main\\VOCdevkit\\VOC2007\\Annotations'#-------------------------------------------------------------##   载入所有的xml#   存储格式为转化为比例后的width,height#-------------------------------------------------------------#print('Load xmls.')data = load_data(path)print(data.shape)data = data * np.array([input_shape[1], input_shape[0]])print(data.shape)print('Load xmls done.')#-------------------------------------------------------------##   使用k聚类算法#-------------------------------------------------------------#print('K-means boxes.')cluster, near   = kmeans(data, anchors_num)print('K-means boxes done.')data            = data * np.array([input_shape[1], input_shape[0]])print(data.shape)cluster         = cluster * np.array([input_shape[1], input_shape[0]])#-------------------------------------------------------------##   绘图#-------------------------------------------------------------#for j in range(anchors_num):plt.scatter(data[near == j][:,0], data[near == j][:,1])plt.scatter(cluster[j][0], cluster[j][1], marker='x', c='black')plt.savefig("kmeans_for_anchors.jpg")plt.show()print('Save kmeans_for_anchors.jpg in root dir.')cluster = cluster[np.argsort(cluster[:, 0] * cluster[:, 1])]print('avg_ratio:{:.2f}'.format(avg_iou(data, cluster)))print(cluster)f = open("yolo_anchors.txt", 'w')row = np.shape(cluster)[0]for i in range(row):if i == 0:x_y = "%d,%d" % (cluster[i][0], cluster[i][1])else:x_y = ", %d,%d" % (cluster[i][0], cluster[i][1])f.write(x_y)f.close()

2.Kmeans++聚类算法

重新思考Anchor Box估计

在这里插入图片描述

代码实现

def bboxesOverRation(bboxesA,bboxesB):"""功能等同于matlab的函数bboxesOverRationbboxesA:M*4 array,形如[x,y,w,h]排布bboxesB: N*4 array,形如[x,y,w,h]排布"""bboxesA = np.array(bboxesA.astype('float'))bboxesB = np.array(bboxesB.astype('float'))M = bboxesA.shape[0]N = bboxesB.shape[0]areasA = bboxesA[:,2]*bboxesA[:,3]areasB = bboxesB[:,2]*bboxesB[:,3]xA = bboxesA[:,0]+bboxesA[:,2]yA = bboxesA[:,1]+bboxesA[:,3]xyA = np.stack([xA,yA]).transpose()xyxyA = np.concatenate((bboxesA[:,:2],xyA),axis=1)xB = bboxesB[:,0] +bboxesB[:,2]yB = bboxesB[:,1]+bboxesB[:,3]xyB = np.stack([xB,yB]).transpose()xyxyB = np.concatenate((bboxesB[:,:2],xyB),axis=1)iouRatio = np.zeros((M,N))for i in range(M):for j in range(N):x1 = max(xyxyA[i,0],xyxyB[j,0]);x2 = min(xyxyA[i,2],xyxyB[j,2]);y1 = max(xyxyA[i,1],xyxyB[j,1]);y2 = min(xyxyA[i,3],xyxyB[j,3]);Intersection = max(0,(x2-x1))*max(0,(y2-y1));Union = areasA[i]+areasB[j]-Intersection;iouRatio[i,j] = Intersection/Union; return iouRatiodef estimateAnchorBoxes(trainingData,numAnchors=9):'''功能:kmeans++算法估计anchor,类似于matlab函数estimateAnchorBoxes,当trainingData数据量较大时候,自写的kmeans迭代循环效率较低,matlab的estimateAnchorBoxes得出anchors较快,但meanIOU较低,然后乘以实际box的ratio即可。此算法由于优化是局部,易陷入局部最优解,结果不一致属正常cuixingxing150@gmail.comExample: import scipy.io as scipodata = scipo.loadmat(r'D:\Matlab_files\trainingData.mat')trainingData = data['temp']meanIoUList = []for numAnchor in np.arange(1,16):anchorBoxes,meanIoU = estimateAnchorBoxes(trainingData,numAnchors=numAnchor)meanIoUList.append(meanIoU)plt.plot(np.arange(1,16),meanIoUList,'ro-')plt.ylabel("Mean IoU")plt.xlabel("Number of Anchors")plt.title("Number of Anchors vs. Mean IoU")Parameters----------trainingData : numpy 类型形如[x,y,w,h]排布,M*4大小二维矩阵numAnchors : int, optional估计的anchors数量. The default is 9.Returns-------anchorBoxes : numpy类型形如[w,h]排布,N*2大小矩阵.meanIoU : scalar 标量DESCRIPTION.'''numsObver = trainingData.shape[0]xyArray = np.zeros((numsObver,2))trainingData[:,0:2] = xyArrayassert(numsObver>=numAnchors)# kmeans++# init centroids = [] # 初始化中心,kmeans++centroid_index = np.random.choice(numsObver, 1)centroids.append(trainingData[centroid_index])while len(centroids)<numAnchors:minDistList = []for box in trainingData:box = box.reshape((-1,4))minDist = 1for centroid in centroids:centroid = centroid.reshape((-1,4))ratio = (1-bboxesOverRation(box,centroid)).item()if ratio<minDist:minDist = ratiominDistList.append(minDist)sumDist = np.sum(minDistList)prob = minDistList/sumDist idx = np.random.choice(numsObver,1,replace=True,p=prob)centroids.append(trainingData[idx])# kmeans 迭代聚类maxIterTimes = 100iter_times = 0while True:minDistList = []minDistList_ind = []for box in trainingData:box = box.reshape((-1,4))minDist = 1box_belong = 0for i,centroid in enumerate(centroids):centroid = centroid.reshape((-1,4))ratio = (1-bboxesOverRation(box,centroid)).item()if ratio<minDist:minDist = ratiobox_belong = iminDistList.append(minDist)minDistList_ind.append(box_belong)centroids_avg = []for _ in range(numAnchors):centroids_avg.append([])for i,anchor_id in enumerate(minDistList_ind):centroids_avg[anchor_id].append(trainingData[i])err = 0for i in range(numAnchors):if len(centroids_avg[i]):temp = np.mean(centroids_avg[i],axis=0)err +=  np.sqrt(np.sum(np.power(temp-centroids[i],2)))centroids[i] = np.mean(centroids_avg[i],axis=0)iter_times+=1if iter_times>maxIterTimes or err==0:breakanchorBoxes = np.array([x[2:] for x in centroids])meanIoU = 1-np.mean(minDistList)return anchorBoxes,meanIoU

http://chatgpt.dhexx.cn/article/pLB4x8eR.shtml

相关文章

anchors如何获得_Yolov3通过k-means聚类得到自己数据的anchors

本文代码参考: https://github.com/lars76/kmeans-anchor-boxes Yolov3中默认的9个anchors是作者通过对voc数据聚类得到的。 anchors 10,14, 23,27, 37,58, 81,82, 135,169, 344,319 不过&#xff0c;当我们训练自己的数据时&#xff0c;如果也采用默认的anchors&#xff0c;可…

Unity 锚点 Anchors

锚点介绍 锚点是Rect Transform组件中的属性&#xff0c;用于描述当前物体相对于父物体的对齐方式。 选中一个UI元素&#xff0c;就会显示其父物体的矩形框以及相对于父物体的锚点。 锚点只能位于父物体的矩形框之内。 锚点表现为四个相对出现的小三角形&#xff0c; 它们时而…

QML anchors 锚布局

锚布局 锚布局有7种锚线 anchors.leftanchors.rightanchors.topanchors.bottomanchors.horizontalCenteranchors.verticalCenteranchors.baseline 5种锚边距 anchors.leftMarginanchors.rightMarginanchors.topMarginanchors.bottomMarginanchors.margins 3种锚偏移 anchor…

anchors生成

关于修改anchor anchor与图片的输入分辨率有关系。 You should use this repository to get anchors: https://github.com/AlexeyAB/darknet By using this command for Yolo v3 (or v2): ./darknet detector calc_anchors data/hand.data -num_of_clusters 9 -width 720 -he…

使用k-means聚类anchors

在之前讲yolo理论基础知识时有提到过&#xff0c;从yolov2开始使用的anchors都是通过聚类得到的。如果想了解更多yolo相关的知识可以看看我在bilibili上录得视频&#xff1a;https://www.bilibili.com/video/BV1yi4y1g7ro 今天补下之前没有细讲的聚类anchors相关知识&#xff…

细说物体检测中的Anchors

点击上方“AI公园”&#xff0c;关注公众号&#xff0c;选择加“星标“或“置顶” 作者&#xff1a;Raghul Asokan 编译&#xff1a;ronghuaiyang 导读 给大家再次解释一下Anchors在物体检测中的作用。 今天&#xff0c;我将讨论在物体检测器中引入的一个优雅的概念 —— Ancho…

带图讲解,深度学习YOLO里面的anchors的进阶理解

如果有了解过yolo网络&#xff0c;那肯定也听说过anchors&#xff0c;当然anchors这个概念布置在YOLO里面才有&#xff0c;在其他的目标检测中也存在anchors这个概念。对于anchors计算的一些公式这篇文章就不进行讲解了&#xff0c;这篇文章主要是讲在训练网络模型过程中anchor…

Linux终端的网易云音乐——musicbox

网易云音乐是听歌的不错的选择&#xff0c;如果能够在命令行听歌就更cool了。特来推荐musicbox。 网易云音乐的musicbox是网易云音乐命令行版本&#xff0c;这款命令行的客户端使用 Python 构建&#xff0c;以 mpg123 作为播放后端。提供了很多使用的功能&#xff0c;如&#x…

MusicStore-2

1.按照MusicStore-1步骤创建mvc项目&#xff0c;并初始化数据库 2.修改HomeController using Chapter8.Models; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc;namespace Chapter8.Controllers {public class…

音乐i网站

开发工具(eclipse/idea/vscode等)&#xff1a; 数据库(sqlite/mysql/sqlserver等)&#xff1a; 功能模块(请用文字描述&#xff0c;至少200字) &#xff1a;

musicbox(暂停/启动,停止,下一曲上一首)

主界面 按下开始 按下暂停 按下停止 下一首 上一首 代码 activity_main.xml <?xml version"1.0" encoding"utf-8"?> <LinearLayout xmlns:android"http://schemas.android.com/apk/res/android"android:orientation"vertical&…

node-webkit-MusicBox 基于nwjs ,html5 ,制作的音乐盒子

太长&#xff1f;单击目录直接去看最终效果&#xff0c;在最下边 文件下载地址&#xff1a;http://download.csdn.net/detail/u013934914/9180053 1.思路&#xff08;简单设想&#xff09; index.html 实现 对页面的显示&#xff0c;并调用绑定ymusic.js中的方法 需要&…

算数计算机音乐模拟器,Musicalculator

musicalculatorapp它是一个音乐旋律软件&#xff0c;在这上面你可以随时随地的记录你有灵感时创作出来的乐谱&#xff0c;还可以放好听的音色包进行自动的弹奏&#xff0c;还可以根据自己的想法设定速度音长&#xff0c;这一款非常的适合喜爱音乐的用户。该应用只是一款音乐计算…

HTML5 CSS3实战——自定义音乐播放器(一)

前几天才刚开始接触HTML5和CSS3。学习了一下里面的一些炫酷的新特性。不过&#xff0c;对于原生的HTML5的媒体播放器&#xff0c;真的不得不吐槽&#xff1a;就三个按钮 界面还那么丑。所以觉得自己整一个好看的播放器。老话说&#xff1a;说不如干&#xff0c;纸上谈兵终觉浅。…

NetEase MusicBox —— Linux系统里的网易云音乐(转载)

功能特性 320kbps的高品质音乐 歌曲&#xff0c;艺术家&#xff0c;专辑检索 网易 22 个歌曲排行榜 网易新碟推荐 网易精选歌单 网易 DJ 节目 私人歌单&#xff0c;每日推荐 随心打碟 本地收藏&#xff0c;随时加 ? 播放进度及播放模式显示 Vimer 式快捷键让操作丝般顺滑 可使…

MusicBox - 仿千千静听

大学毕业时业余之作 最新下载地址&#xff1a; 匿名提取文件连接 http://pickup.mofile.com/5412819180446197 或登录Mofile&#xff0c;使用提取码 5412819180446197 提取文件 MusicBox 停止开发&#xff01;&#xff01; 淘宝开卖源代码 有意者 http://item.taobao.co…

音乐播放器

用HTML做了个音乐播放器&#xff0c;可以循环播放&#xff0c;选择歌曲&#xff0c;以及自动播放下一首&#xff0c;运用了js和json知识&#xff0c;下面是效果图和源码&#xff0c;有兴趣的可以试试哦 效果图&#xff1a; 源码&#xff1a;html <span style"color:#9…

MusicPlay播放器

文章目录 一丶前端布局二丶Activity三丶Service实验演示 一丶前端布局 Layout的框架 一个自定义的音乐播放器&#xff0c;页面布局大致如下 二丶Activity 首先定义控件 // 获取界面中显示歌曲标题、作者文本框TextView title, author;// 喜欢&#xff0c;播放&#xff0c;暂…

MusicPlay 音乐播放器(纯前端)

纯Css,js前端音乐播放器,界面UI比较好。我特别喜欢,适合二次开发,调用了网易云第三方接口以及将歌曲链接导出可以访问的歌曲链接,实现了异步歌曲搜索播放,以及异步显示歌词等.结合html5 新特性实现歌曲暂停,下一首,快进等等.为大二前端练手项目.采用渐变质背景 是前端练手的好…

HTML5+JS实现简易的音乐播放器

HTML5JS实现简易的音乐播放器 播放器实现的功能 播放/暂停音乐切换歌曲&#xff0c;上/下一首歌音量最大或静音音乐播放时间实时变化进度条拖拽歌曲图片切换 播放器效果展示 代码展示 html <div class"musicBox" id"musicBox"><audio src"…