Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问如何用不同的数据集train 实时识别数字 #1

Open
zhaojianghe16 opened this issue Apr 4, 2019 · 5 comments
Open

请问如何用不同的数据集train 实时识别数字 #1

zhaojianghe16 opened this issue Apr 4, 2019 · 5 comments

Comments

@zhaojianghe16
Copy link

你好~
我重新找了一些不同的数字(背景是黑色然后字体是白色的)
我将他们都按照你原来的命名方式放到了对应的train,test文件夹里面。名称都是一样的,只有图片内容换了(我的图片也是28*28)。
但是pycharm给出error.
WeChat Image_20190404130752 截图上面Train是你的数据集,下面的train2是我的数据集。

不知道为什么只有图片不同,但是最终print出来的dimension是不一样的。数字1, 2 只是加进去标识print的顺序而已。我发现changDim会让array最后多了一个3. 你的是**(28, 28)**, 我的是(28, 28, 3)。 最后会导致我有(1, 28, 28, 1, 3)。
请问怎么样才能用新的数据集去重新train model呢? 这是我的毕业设计内容之一,如果能有你的帮忙就太好了。谢谢!

下面是我用来找不同时候用的code。

def changeDim(img):
img=np.expand_dims(img,axis=2)
img=np.expand_dims(img,axis=0)
return img
######准备数据
num_classes = 11 #类别
batch_size = 120 #批量大小
epochs = 60 #训练次数

#img2 = cv2.imread("5.jpg")
#print(img2.shape)
#img2= changeDim(img2)
#print(img2.shape)

img = cv2.imread("pic.jpg", cv2.IMREAD_COLOR)

img = cv2.imread("pic.jpg", cv2.IMREAD_GRAYSCALE)

img = cv2.imread("pic.jpg", cv2.IMREAD_UNCHANGED)

def loadDataset(imgpath, pathtype):
# 准备图像数据
images = loadImages(imgpath[0])
print('1', images.shape)
images = changeDim(images)
print('2', images.shape)
for single in imgpath[1:]:
img = loadImages(single)
img = changeDim(img)
images =np.append(images,img, axis = 0)
# 准备标记
labels = []
pattern = re.compile(pathtype+r"\(\d{1,2})")
for single in imgpath:
label = pattern.findall(single)
labels.append(int(label[0]))
return np.array(images), np.array(labels)
def loadImages(imgpath):
img = misc.imread(imgpath)
if img is None:
return None
img = img.astype('float32')
img/=255
return img

imgfiles = './Train//.jpg'
imgpath = glob.glob(imgfiles)
print(imgpath)
images, labels = loadDataset(imgpath,'Train')
labels = keras.utils.to_categorical(labels, num_classes)
print(images.shape, labels.shape)

imgfiles2 = './Train2//.jpg'
imgpath = glob.glob(imgfiles2)
print(imgpath)
images, labels = loadDataset(imgpath,'Train')
labels = keras.utils.to_categorical(labels, num_classes)
print(images.shape, labels.shape)

imgfiles3 = '5.jpg'
imgpath = glob.glob(imgfiles3)
print(imgpath)
images, labels = loadDataset(imgpath,'Train')

labels = keras.utils.to_categorical(labels, num_classes)
print(images.shape, labels.shape)

@xrayzone
Copy link

xrayzone commented Apr 9, 2019 via email

@Sherlockzw
Copy link

哇,这个是怎么回复的?我也收的到😂😂😂

@xrayzone
Copy link

xrayzone commented Apr 9, 2019 via email

@zhaojianghe16
Copy link
Author

@CodeSama346623 你好,请问看到我的提问了吗? 希望可以看到你的建议,谢谢。

@xrayzone @Sherlockzw 你们可以用@来回复。可能是你们以前post过一些提问所以subscribe就收到邮件了吧。

@Sherlockzw
Copy link

Sherlockzw commented Apr 10, 2019

哇~第一次知道github还有这功能,小哥哥最近好像比较忙,好久好久没见他上线了,他可能一时半会儿看不到吧。。之前也有过四个月没上线,emmmm你要是不急的话可以等等。。。。。着急的话先问一下别人吧 @zhaojianghe16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants