运行错误
In C:\Users\26246\Anaconda3\lib\site-packages\matplotlib\mpl-data\stylelib\_classic_test.mplstyle:
The text.latex.preview rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
In C:\Users\26246\Anaconda3\lib\site-packages\matplotlib\mpl-data\stylelib\_classic_test.mplstyle:
The mathtext.fallback_to_cm rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
In C:\Users\26246\Anaconda3\lib\site-packages\matplotlib\mpl-data\stylelib\_classic_test.mplstyle: Support for setting the 'mathtext.fallback_to_cm' rcParam is deprecated since 3.3 and will be removed two minor releases later; use 'mathtext.fallback : 'cm' instead.
In C:\Users\26246\Anaconda3\lib\site-packages\matplotlib\mpl-data\stylelib\_classic_test.mplstyle:
The validate_bool_maybe_none function was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
In C:\Users\26246\Anaconda3\lib\site-packages\matplotlib\mpl-data\stylelib\_classic_test.mplstyle:
The savefig.jpeg_quality rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
In C:\Users\26246\Anaconda3\lib\site-packages\matplotlib\mpl-data\stylelib\_classic_test.mplstyle:
The keymap.all_axes rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
In C:\Users\26246\Anaconda3\lib\site-packages\matplotlib\mpl-data\stylelib\_classic_test.mplstyle:
The animation.avconv_path rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
In C:\Users\26246\Anaconda3\lib\site-packages\matplotlib\mpl-data\stylelib\_classic_test.mplstyle:
The animation.avconv_args rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
Traceback (most recent call last):
File "c:/Users/26246/Desktop/four_flower-master/gui.py", line 74, in OnSelect
print(dialog.GetPath())
wx._core.wxAssertionError: C++ assertion ""!HasFlag(wxFD_MULTIPLE)"" failed at C:\PROJECTS\bb2\dist-win64-py36\build\ext\wxWidgets\include\wx/filedlg.h(109) in wxFileDialogBase::GetPath(): When using wxFD_MULTIPLE, must call GetPaths() instead
其中错误信息中的路径“ C:\PROJECTS\bb2\dist-win64-py36\build\ext\wxWidgets\include\wx/filedlg.h(109)”不是我的路径,应该是作者的路径,不知道怎么修改
提供gui.py代码
#!/bin/python
import wx
from test import evaluate_one_image
from PIL import Image
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
import os
class HelloFrame(wx.Frame):
def __init__(self,*args,**kw):
super(HelloFrame,self).__init__(*args,**kw)
pnl = wx.Panel(self)
self.pnl = pnl
st = wx.StaticText(pnl, label="花朵识别", pos=(200, 0))
font = st.GetFont()
font.PointSize += 10
font = font.Bold()
st.SetFont(font)
# 选择图像文件按钮
btn = wx.Button(pnl, -1, "select")
btn.Bind(wx.EVT_BUTTON, self.OnSelect)
self.makeMenuBar()
self.CreateStatusBar()
self.SetStatusText("Welcome to flower world")
def makeMenuBar(self):
fileMenu = wx.Menu()
helloItem = fileMenu.Append(-1, "&Hello...\tCtrl-H",
"Help string shown in status bar for this menu item")
fileMenu.AppendSeparator()
exitItem = fileMenu.Append(wx.ID_EXIT)
helpMenu = wx.Menu()
aboutItem = helpMenu.Append(wx.ID_ABOUT)
menuBar = wx.MenuBar()
menuBar.Append(fileMenu, "&File")
menuBar.Append(helpMenu, "Help")
self.SetMenuBar(menuBar)
self.Bind(wx.EVT_MENU, self.OnHello, helloItem)
self.Bind(wx.EVT_MENU, self.OnExit, exitItem)
self.Bind(wx.EVT_MENU, self.OnAbout, aboutItem)
def OnExit(self, event):
self.Close(True)
def OnHello(self, event):
wx.MessageBox("你好呀!")
def OnAbout(self, event):
"""Display an About Dialog"""
wx.MessageBox("有错误+qq2624637450",
"您好!",
wx.OK | wx.ICON_INFORMATION)
def OnSelect(self, event):
wildcard = "image source(*.jpg)|*.jpg|" \
"Compile Python(*.pyc)|*.pyc|" \
"All file(*.*)|*.*"
dialog = wx.FileDialog(None, "Choose a file", os.getcwd(),
"", wildcard, wx.ID_OPEN)
if dialog.ShowModal() == wx.ID_OK:
print(dialog.GetPath())
img = Image.opendialog.GetPath()
imag = img.resize([64, 64])
image = np.array(imag)
result = evaluate_one_image(image)
result_text = wx.StaticText(self.pnl, label=result, pos=(320, 0))
font = result_text.GetFont()
font.PointSize += 8
result_text.SetFont(font)
self.initimage(name= dialog.GetPath())
# 生成图片控件
def initimage(self, name):
imageShow = wx.Image(name, wx.BITMAP_TYPE_ANY)
sb = wx.StaticBitmap(self.pnl, -1, imageShow.ConvertToBitmap(), pos=(0,30), size=(600,400))
return sb
if __name__ == '__main__':
app = wx.App()
frm = HelloFrame(None, title='flower wolrd', size=(1000,600))
frm.Show()
app.MainLoop()
由于在dialog中使用了wx.ID_OPEN这个style参数导致错误的发生,改用wx.FD_OPEN。将71行的代码改成:dialog = wx.FileDialog(None, "Choose a file", os.getcwd(),"", wildcard, wx.FD_OPEN),看能否解决问题。
没懂,报错不是说GetPath(): When using wxFD_MULTIPLE, must call GetPaths() instead
改下试下
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632
报错
(base) C:\Users\26246\Desktop\four_flower-master>C:/Users/26246/Anaconda3/python.exe c:/Users/26246/Desktop/four_flower-master/gui.py
In C:\Users\26246\Anaconda3\lib\site-packages\matplotlib\mpl-data\stylelib\_classic_test.mplstyle:
The text.latex.preview rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
In C:\Users\26246\Anaconda3\lib\site-packages\matplotlib\mpl-data\stylelib\_classic_test.mplstyle:
The mathtext.fallback_to_cm rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
In C:\Users\26246\Anaconda3\lib\site-packages\matplotlib\mpl-data\stylelib\_classic_test.mplstyle: Support for setting the 'mathtext.fallback_to_cm' rcParam is deprecated since 3.3 and will be removed two minor releases later; use 'mathtext.fallback : 'cm' instead.
In C:\Users\26246\Anaconda3\lib\site-packages\matplotlib\mpl-data\stylelib\_classic_test.mplstyle:
The validate_bool_maybe_none function was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
In C:\Users\26246\Anaconda3\lib\site-packages\matplotlib\mpl-data\stylelib\_classic_test.mplstyle:
The savefig.jpeg_quality rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
In C:\Users\26246\Anaconda3\lib\site-packages\matplotlib\mpl-data\stylelib\_classic_test.mplstyle:
The keymap.all_axes rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
In C:\Users\26246\Anaconda3\lib\site-packages\matplotlib\mpl-data\stylelib\_classic_test.mplstyle:
The animation.avconv_path rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
In C:\Users\26246\Anaconda3\lib\site-packages\matplotlib\mpl-data\stylelib\_classic_test.mplstyle:
The animation.avconv_args rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
['C:\\Users\\26246\\Desktop\\u=2638777768,2967950692&fm=26&gp=0.jpg']
Traceback (most recent call last):
File "C:\Users\26246\Anaconda3\lib\site-packages\PIL\Image.py", line 2813, in open
fp.seek(0)
AttributeError: 'list' object has no attribute 'seek'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:/Users/26246/Desktop/four_flower-master/gui.py", line 76, in OnSelect
img = Image.open(dialog.GetPaths())
File "C:\Users\26246\Anaconda3\lib\site-packages\PIL\Image.py", line 2815, in open
fp = io.BytesIO(fp.read())
AttributeError: 'list' object has no attribute 'read'
目前的gui.py代码
#!/bin/python
import wx
from test import evaluate_one_image
from PIL import Image
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
import os
class HelloFrame(wx.Frame):
def __init__(self,*args,**kw):
super(HelloFrame,self).__init__(*args,**kw)
pnl = wx.Panel(self)
self.pnl = pnl
st = wx.StaticText(pnl, label="花朵识别", pos=(200, 0))
font = st.GetFont()
font.PointSize += 10
font = font.Bold()
st.SetFont(font)
# 选择图像文件按钮
btn = wx.Button(pnl, -1, "select")
btn.Bind(wx.EVT_BUTTON, self.OnSelect)
self.makeMenuBar()
self.CreateStatusBar()
self.SetStatusText("Welcome to flower world")
def makeMenuBar(self):
fileMenu = wx.Menu()
helloItem = fileMenu.Append(-1, "&Hello...\tCtrl-H",
"Help string shown in status bar for this menu item")
fileMenu.AppendSeparator()
exitItem = fileMenu.Append(wx.ID_EXIT)
helpMenu = wx.Menu()
aboutItem = helpMenu.Append(wx.ID_ABOUT)
menuBar = wx.MenuBar()
menuBar.Append(fileMenu, "&File")
menuBar.Append(helpMenu, "Help")
self.SetMenuBar(menuBar)
self.Bind(wx.EVT_MENU, self.OnHello, helloItem)
self.Bind(wx.EVT_MENU, self.OnExit, exitItem)
self.Bind(wx.EVT_MENU, self.OnAbout, aboutItem)
def OnExit(self, event):
self.Close(True)
def OnHello(self, event):
wx.MessageBox("你好呀!")
def OnAbout(self, event):
"""Display an About Dialog"""
wx.MessageBox("有错误+qq2624637450",
"您好!",
wx.OK | wx.ICON_INFORMATION)
def OnSelect(self, event):
wildcard = "image source(*.jpg)|*.jpg|" \
"Compile Python(*.pyc)|*.pyc|" \
"All file(*.*)|*.*"
dialog = wx.FileDialog(None, "Choose a file", os.getcwd(),
"", wildcard, wx.ID_OPEN)
if dialog.ShowModal() == wx.ID_OK:
print(dialog.GetPaths())
img = Image.open(dialog.GetPaths())
imag = img.resize([64, 64])
image = np.array(imag)
result = evaluate_one_image(image)
result_text = wx.StaticText(self.pnl, label=result, pos=(320, 0))
font = result_text.GetFont()
font.PointSize += 8
result_text.SetFont(font)
self.initimage(name= dialog.GetPaths())
# 生成图片控件
def initimage(self, name):
imageShow = wx.Image(name, wx.BITMAP_TYPE_ANY)
sb = wx.StaticBitmap(self.pnl, -1, imageShow.ConvertToBitmap(), pos=(0,30), size=(600,400))
return sb
if __name__ == '__main__':
app = wx.App()
frm = HelloFrame(None, title='flower wolrd', size=(1000,600))
frm.Show()
app.MainLoop()
model.py
import tensorflow as tf
def inference(images, batch_size, n_classes):
# 卷积层1
with tf.variable_scope('conv1') as scope:
weights = tf.Variable(tf.truncated_normal(shape=[3, 3, 3, 64], stddev=1.0, dtype=tf.float32),
name='weights', dtype=tf.float32)
biases = tf.Variable(tf.constant(value=0.1, dtype=tf.float32, shape=[64]),
name='biases', dtype=tf.float32)
conv = tf.nn.conv2d(images, weights, strides=[1, 1, 1, 1], padding='SAME')
pre_activation = tf.nn.bias_add(conv, biases)
conv1 = tf.nn.relu(pre_activation, name=scope.name)
# 池化层1
with tf.variable_scope('pooling1_lrn') as scope:
pool1 = tf.nn.max_pool(conv1, ksize=[1, 3, 3, 1], strides=[1, 2, 2, 1], padding='SAME', name='pooling1')
norm1 = tf.nn.lrn(pool1, depth_radius=4, bias=1.0, alpha=0.001 / 9.0, beta=0.75, name='norm1')
# 卷积层2
with tf.variable_scope('conv2') as scope:
weights = tf.Variable(tf.truncated_normal(shape=[3, 3, 64, 16], stddev=0.1, dtype=tf.float32),
name='weights', dtype=tf.float32)
biases = tf.Variable(tf.constant(value=0.1, dtype=tf.float32, shape=[16]),
name='biases', dtype=tf.float32)
conv = tf.nn.conv2d(norm1, weights, strides=[1, 1, 1, 1], padding='SAME')
pre_activation = tf.nn.bias_add(conv, biases)
conv2 = tf.nn.relu(pre_activation, name='conv2')
# 池化层2
# pool2 and norm2
with tf.variable_scope('pooling2_lrn') as scope:
norm2 = tf.nn.lrn(conv2, depth_radius=4, bias=1.0, alpha=0.001 / 9.0, beta=0.75, name='norm2')
pool2 = tf.nn.max_pool(norm2, ksize=[1, 3, 3, 1], strides=[1, 1, 1, 1], padding='SAME', name='pooling2')
# 全连接层3
with tf.variable_scope('local3') as scope:
reshape = tf.reshape(pool2, shape=[batch_size, -1])
dim = reshape.get_shape()[1].value
weights = tf.Variable(tf.truncated_normal(shape=[dim, 128], stddev=0.005, dtype=tf.float32),
name='weights', dtype=tf.float32)
biases = tf.Variable(tf.constant(value=0.1, dtype=tf.float32, shape=[128]),
name='biases', dtype=tf.float32)
local3 = tf.nn.relu(tf.matmul(reshape, weights) + biases, name=scope.name)
# 全连接层4
with tf.variable_scope('local4') as scope:
weights = tf.Variable(tf.truncated_normal(shape=[128, 128], stddev=0.005, dtype=tf.float32),
name='weights', dtype=tf.float32)
biases = tf.Variable(tf.constant(value=0.1, dtype=tf.float32, shape=[128]),
name='biases', dtype=tf.float32)
local4 = tf.nn.relu(tf.matmul(local3, weights) + biases, name='local4')
# dropout层
# with tf.variable_scope('dropout') as scope:
# drop_out = tf.nn.dropout(local4, 0.8)
# Softmax回归层
with tf.variable_scope('softmax_linear') as scope:
weights = tf.Variable(tf.truncated_normal(shape=[128, n_classes], stddev=0.005, dtype=tf.float32),
name='softmax_linear', dtype=tf.float32)
biases = tf.Variable(tf.constant(value=0.1, dtype=tf.float32, shape=[n_classes]),
name='biases', dtype=tf.float32)
softmax_linear = tf.add(tf.matmul(local4, weights), biases, name='softmax_linear')
return softmax_linear
# loss计算
def losses(logits, labels):
with tf.variable_scope('loss') as scope:
cross_entropy = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=logits, labels=labels,
name='xentropy_per_example')
loss = tf.reduce_mean(cross_entropy, name='loss')
tf.summary.scalar(scope.name + '/loss', loss)
return loss
# loss损失值优化
def trainning(loss, learning_rate):
with tf.name_scope('optimizer'):
optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate)
global_step = tf.Variable(0, name='global_step', trainable=False)
train_op = optimizer.minimize(loss, global_step=global_step)
return train_op
# 评价/准确率计算
def evaluation(logits, labels):
with tf.variable_scope('accuracy') as scope:
correct = tf.nn.in_top_k(logits, labels, 1)
correct = tf.cast(correct, tf.float16)
accuracy = tf.reduce_mean(correct)
tf.summary.scalar(scope.name + '/accuracy', accuracy)
return accuracy
非常感谢您使用有问必答服务,为了后续更快速的帮您解决问题,现诚邀您参与有问必答体验反馈。您的建议将会运用到我们的产品优化中,希望能得到您的支持与协助!
速戳参与调研>>>https://t.csdnimg.cn/Kf0y