python3.9是最新的版本,有许多库都没有编译好的安装包,这时候pip会下载源码手动编译
安装好编译环境后是可以编译成功的,但像深度学习框架等大软件包环境非常难配
用linux系统都需要复杂的操作才能编译好,并且不推荐自己编译。
所以建议使用目前最稳定的python3.8, 或兼容性最好的3.7
直接安装没有GPU,只能用CPU。 要用GPU一般要在装tensorlow的时候至少装两个东西,一个是显卡驱动一个是CUDA。你可以试试conda install -c anaconda tensorflow-gpu,我记得好像会自动帮你装上显卡驱动和cuda
from __future__ import division
from Tkinter import *
import tkMessageBox
from PIL import Image, ImageTk
import os
import glob
import random
w0 = 1; #图片原始宽度
h0 = 1; #图片原始高度
# colors for the bboxes
COLORS = ['red', 'blue', 'yellow', 'pink', 'cyan', 'green', 'black']
SIZE = 256, 256
#指定缩放后的图像大小
DEST_SIZE = 500, 500
class LabelTool():
def __init__(self, master):
# set up the main frame
self.parent = master
self.parent.title("LabelTool")
self.frame = Frame(self.parent)
self.frame.pack(fill=BOTH, expand=1)
self.parent.resizable(width = TRUE, height = TRUE)
self.imageDir = ''
self.imageList= []
self.egDir = ''
self.egList = []
self.outDir = ''
self.cur = 0
self.total = 0
self.category = 0
self.imagename = ''
self.labelfilename = ''
self.tkimg = None
self.STATE = {}
self.STATE['click'] = 0
self.STATE['x'], self.STATE['y'] = 0, 0
self.bboxIdList = []
self.bboxId = None
self.bboxList = []
self.hl = None
self.vl = None
self.label = Label(self.frame, text = "Image Dir:")
self.label.grid(row = 0, column = 0, sticky = E)
self.entry = Entry(self.frame)
self.entry.grid(row = 0, column = 1, sticky = W+E)
self.ldBtn = Button(self.frame, text = "Load", command = self.loadDir)
self.ldBtn.grid(row = 0, column = 2, sticky = W+E)
self.mainPanel = Canvas(self.frame, cursor='tcross')
self.mainPanel.bind("Button-1", self.mouseClick)
self.mainPanel.bind("Motion", self.mouseMove)
self.parent.bind("Escape", self.cancelBBox) # press Espace to cancel current bbox
self.parent.bind("s", self.cancelBBox)
self.parent.bind("a", self.prevImage) # press 'a' to go backforward
self.parent.bind("d", self.nextImage) # press 'd' to go forward
self.mainPanel.grid(row = 1, column = 1, rowspan = 4, sticky = W+N)
self.lb1 = Label(self.frame, text = 'Bounding boxes:')
self.lb1.grid(row = 1, column = 2, sticky = W+N)
self.listbox = Listbox(self.frame, width = 28, height = 12)
self.listbox.grid(row = 2, column = 2, sticky = N)
self.btnDel = Button(self.frame, text = 'Delete', command = self.delBBox)
self.btnDel.grid(row = 3, column = 2, sticky = W+E+N)
self.btnClear = Button(self.frame, text = 'ClearAll', command = self.clearBBox)
self.btnClear.grid(row = 4, column = 2, sticky = W+E+N)
self.ctrPanel = Frame(self.frame)
self.ctrPanel.grid(row = 5, column = 1, columnspan = 2, sticky = W+E)
self.prevBtn = Button(self.ctrPanel, text=' Prev', width = 10, command = self.prevImage)
self.prevBtn.pack(side = LEFT, padx = 5, pady = 3)
self.nextBtn = Button(self.ctrPanel, text='Next ', width = 10, command = self.nextImage)
self.nextBtn.pack(side = LEFT, padx = 5, pady = 3)
self.progLabel = Label(self.ctrPanel, text = "Progress: / ")
self.progLabel.pack(side = LEFT, padx = 5)
self.tmpLabel = Label(self.ctrPanel, text = "Go to Image No.")
self.tmpLabel.pack(side = LEFT, padx = 5)
self.idxEntry = Entry(self.ctrPanel, width = 5)
self.idxEntry.pack(side = LEFT)
self.goBtn = Button(self.ctrPanel, text = 'Go', command = self.gotoImage)
self.goBtn.pack(side = LEFT)
self.egPanel = Frame(self.frame, border = 10)
self.egPanel.grid(row = 1, column = 0, rowspan = 5, sticky = N)
self.tmpLabel2 = Label(self.egPanel, text = "Examples:")
self.tmpLabel2.pack(side = TOP, pady = 5)
self.egLabels = []
for i in range(3):
self.egLabels.append(Label(self.egPanel))
self.egLabels[-1].pack(side = TOP)
self.disp = Label(self.ctrPanel, text='')
self.disp.pack(side = RIGHT)
self.frame.columnconfigure(1, weight = 1)
self.frame.rowconfigure(4, weight = 1)
def loadDir(self, dbg = False):
if not dbg:
s = self.entry.get()
self.parent.focus()
self.category = int(s)
else:
s = r'D:\workspace\python\labelGUI'
print 'self.category =%d' %(self.category )
self.imageDir = os.path.join(r'./images', '%03d' %(self.category))
print(self.imageDir)
self.imageList = glob.glob(os.path.join(self.imageDir, '*.jpg'))
if len(self.imageList) == 0:
print 'No .jpg images found in the specified dir!'
return
else:
print 'num=%d' %(len(self.imageList))
self.cur = 1
self.total = len(self.imageList)
self.outDir = os.path.join(r'./labels', '%03d' %(self.category))
if not os.path.exists(self.outDir):
os.mkdir(self.outDir)
self.egDir = os.path.join(r'./Examples', '%03d' %(self.category))
filelist = glob.glob(os.path.join(self.egDir, '*.jpg'))
self.tmp = []
self.egList = []
random.shuffle(filelist)
for (i, f) in enumerate(filelist):
if i == 3:
break
im = Image.open(f)
r = min(SIZE[0] / im.size[0], SIZE[1] / im.size[1])
new_size = int(r * im.size[0]), int(r * im.size[1])
self.tmp.append(im.resize(new_size, Image.ANTIALIAS))
self.egList.append(ImageTk.PhotoImage(self.tmp[-1]))
self.egLabels[i].config(image = self.egList[-1], width = SIZE[0], height = SIZE[1])
self.loadImage()
print '%d images loaded from %s' %(self.total, s)
def loadImage(self):
imagepath = self.imageList[self.cur - 1]
pil_image = Image.open(imagepath)
# get the size of the image
#获取图像的原始大小
global w0,h0
w0, h0 = pil_image.size
#缩放到指定大小
pil_image = pil_image.resize((DEST_SIZE[0], DEST_SIZE[1]), Image.ANTIALIAS)
#pil_image = imgresize(w, h, w_box, h_box, pil_image)
self.img = pil_image
self.tkimg = ImageTk.PhotoImage(pil_image)
self.mainPanel.config(width = max(self.tkimg.width(), 400), height = max(self.tkimg.height(), 400))
self.mainPanel.create_image(0, 0, image = self.tkimg, anchor=NW)
self.progLabel.config(text = "%04d/%04d" %(self.cur, self.total))
# load labels
self.clearBBox()
self.imagename = os.path.split(imagepath)[-1].split('.')[0]
labelname = self.imagename + '.txt'
self.labelfilename = os.path.join(self.outDir, labelname)
bbox_cnt = 0
if os.path.exists(self.labelfilename):
with open(self.labelfilename) as f:
for (i, line) in enumerate(f):
if i == 0:
bbox_cnt = int(line.strip())
continue
print line
tmp = [(t.strip()) for t in line.split()]
print "********************"
print DEST_SIZE
#tmp = (0.1, 0.3, 0.5, 0.5)
print "tmp[0,1,2,3]===%.2f, %.2f, %.2f, %.2f" %(float(tmp[0]), float(tmp[1]), float(tmp[2]), float(tmp[3]))
#print "%.2f,%.2f,%.2f,%.2f" %(tmp[0] tmp[1] tmp[2] tmp[3] )
print "********************"
#tx = (10, 20, 30, 40)
#self.bboxList.append(tuple(tx))
self.bboxList.append(tuple(tmp))
tmp[0] = float(tmp[0])
tmp[1] = float(tmp[1])
tmp[2] = float(tmp[2])
tmp[3] = float(tmp[3])
tx0 = int(tmp[0]*DEST_SIZE[0])
ty0 = int(tmp[1]*DEST_SIZE[1])
tx1 = int(tmp[2]*DEST_SIZE[0])
ty1 = int(tmp[3]*DEST_SIZE[1])
print "tx0, ty0, tx1, ty1"
print tx0, ty0, tx1, ty1
tmpId = self.mainPanel.create_rectangle(tx0, ty0, tx1, ty1,\
width = 2, \
outline = COLORS[(len(self.bboxList)-1) % len(COLORS)])
self.bboxIdList.append(tmpId)
self.listbox.insert(END, '(%.2f,%.2f)-(%.2f,%.2f)' %(tmp[0], tmp[1], tmp[2], tmp[3]) )
# self.listbox.insert(END, '(%d, %d) - (%d, %d)' %(tmp[0], tmp[1], tmp[2], tmp[3]))
self.listbox.itemconfig(len(self.bboxIdList) - 1, fg = COLORS[(len(self.bboxIdList) - 1) % len(COLORS)])
def saveImage(self):
print self.bboxList
with open(self.labelfilename, 'w') as f:
f.write('%d\n' %len(self.bboxList))
for bbox in self.bboxList:
f.write(' '.join(map(str, bbox)) + '\n')
print 'Image No. %d saved' %(self.cur)
def mouseClick(self, event):
if self.STATE['click'] == 0:
self.STATE['x'], self.STATE['y'] = event.x, event.y
else:
x1, x2 = min(self.STATE['x'], event.x), max(self.STATE['x'], event.x)
y1, y2 = min(self.STATE['y'], event.y), max(self.STATE['y'], event.y)
x1, x2 = x1 / DEST_SIZE[0], x2 / DEST_SIZE[0];
y1, y2 = y1 / DEST_SIZE[1], y2 / DEST_SIZE[1];
self.bboxList.append((x1, y1, x2, y2))
self.bboxIdList.append(self.bboxId)
self.bboxId = None
self.listbox.insert(END, '(%.2f, %.2f)-(%.2f, %.2f)' %(x1, y1, x2, y2))
self.listbox.itemconfig(len(self.bboxIdList) - 1, fg = COLORS[(len(self.bboxIdList) - 1) % len(COLORS)])
self.STATE['click'] = 1 - self.STATE['click']
if __name__ == '__main__':
root = Tk()
tool = LabelTool(root)
root.mainloop()
需要安装。
1。安装系统。1。安装ubuntu。具体安装省略,记录一个小bug,可能在给有独立显卡的台式机安装ubuntu双系统时遇到:在安装时,使用U盘启动这步,直接选择tryubuntu或installubuntu都会出现黑屏的问题。解决方法:将光标移动到installubuntu一项上,按e键,会进入一个可编辑的界面,将quietsplash修改为nouveau。modeset=0nomodeset,然后按ctrl+x进入安装。之后在ubuntu安装nvidia驱动后,就正常了。如果没有安装驱动,每次进入前,都要用同样的方法将上面的quietsplash修改。2。配置nvidia显卡。具体分为两步:安装nvidia驱动,如果是图形界面的话,在SoftwareUpdates中的AdditionalDrivers中选择合适的驱动安装即可。在官网下载cudnn并安装。2。创建和登录用户。在linux上创建自己的用户,方便管理代码和安装应用。比如我们想要创建一个用户名是haha,密码是123456的用户,命令如下:添加用户:useradd-d/home/haha-mhaha。设置密码(只有设置密码之后,才能登录用户):passwdhaha,然后输入密码。然后就可以通过sshhaha@your_ip的方式登录服务器了。登录后也可以设置bash:chsh-s/bin/bash或修改为zsh。加入root权限:使用apt下载时,如果出现不在sudoers文件中的报错,则需要将用户加入sudoers,执行sudovim/etc/sudoers命令,rootALL=(ALL)ALL的下一行加入hahaALL=(ALL)ALL,然后保存。删除用户:userdel-rhaha。
您好,Matlab是一款非常强大的数学软件,但是它并不支持深度学习网络的安装。深度学习网络的安装需要安装一些其他的软件,比如TensorFlow,Keras,PyTorch等。这些软件都有自己的安装文档,您可以根据文档进行安装。此外,您还可以使用一些第三方工具,比如Anaconda,来安装深度学习网络。Anaconda可以让您轻松安装和管理各种软件,从而让您更轻松地安装深度学习网络。
应该是你的CUDA 运行库的路径不对,如果是Windows,请查看 系统属性/高级/环境变量 里面的CUDA_PATH是否正确。
友情声明:本文内容由用户自发奉献,本站文章量较多,不能保证每篇文章的绝对合法性,若您发觉违规/侵权内容,请尽快联系我们删除。