- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
下面是我的多图像分类代码。我收到错误;我认为这是因为加载和其他地方尺寸不匹配。
错误消息从代码结束处开始。有人能看出问题所在吗?
#importing necessary packages
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
from PIL import Image
import tflearn
import tensorflow as tf
import tflearn
#for writing text files
import glob
import os
import random
#reading images from a text file
from tflearn.data_utils import image_preloader
import math
IMAGE_FOLDER = 'C:/Users/kdeepshi/Desktop/PyforE/Face-Detection/Train'
TRAIN_DATA = 'C:/Users/kdeepshi/Desktop/PyforE/Face-Detection/training_data.txt'
TEST_DATA = 'C:/Users/kdeepshi/Desktop/PyforE/Face-Detection/test_data.txt'
VALIDATION_DATA = 'C:/Users/kdeepshi/Desktop/PyforE/Face-Detection/validation_data.txt'
train_proportion=0.7
test_proportion=0.2
validation_proportion=0.1
#read the image directories
filenames_image = os.listdir(IMAGE_FOLDER)
#shuffling the data is important otherwise the model will be fed with a single class data for a long time and
#network will not learn properly
random.shuffle(filenames_image)
#total number of images
total=len(filenames_image)
## *****training data********
fr = open(TRAIN_DATA, 'w')
train_files=filenames_image[0: int(train_proportion*total)]
for filename in train_files:
if filename[0:4] == 'Mark':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 0\n')
elif filename[0:5] == 'lucas':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 1\n')
elif filename[0:3] == 'Ann':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 2\n')
elif filename[0:5] == 'Henry':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 3\n')
elif filename[0:5] == 'Hanna':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 4\n')
elif filename[0:4] == 'Jack':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 5\n')
elif filename[0:5] == 'Harry':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 6\n')
elif filename[0:3] == 'Lui':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 7\n')
elif filename[0:6] == 'Karlos':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 8\n')
elif filename[0:4] == 'Guan':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 9\n')
fr.close()
## *****testing data********
fr = open(TEST_DATA, 'w')
test_files=filenames_image[int(math.ceil(train_proportion*total)):int(math.ceil((train_proportion+test_proportion)*total))]
for filename in test_files:
if filename[0:4] == 'Mark':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 0\n')
elif filename[0:5] == 'lucas':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 1\n')
elif filename[0:3] == 'Ann':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 2\n')
elif filename[0:5] == 'Henry':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 3\n')
elif filename[0:5] == 'Hanna':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 4\n')
elif filename[0:4] == 'Jack':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 5\n')
elif filename[0:5] == 'Harry':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 6\n')
elif filename[0:3] == 'Lui':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 7\n')
elif filename[0:6] == 'Karlos':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 8\n')
elif filename[0:4] == 'Guan':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 9\n')
fr.close()
## *****validation data********
fr = open(VALIDATION_DATA, 'w')
valid_files=filenames_image[int(math.ceil((train_proportion+test_proportion)*total)):total]
for filename in valid_files:
if filename[0:4] == 'Mark':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 0\n')
elif filename[0:5] == 'lucas':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 1\n')
elif filename[0:3] == 'Ann':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 2\n')
elif filename[0:5] == 'Henry':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 3\n')
elif filename[0:5] == 'Hanna':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 4\n')
elif filename[0:4] == 'Jack':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 5\n')
elif filename[0:5] == 'Harry':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 6\n')
elif filename[0:3] == 'Lui':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 7\n')
elif filename[0:6] == 'Karlos':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 8\n')
elif filename[0:4] == 'Guan':
fr.write(IMAGE_FOLDER + '/'+ filename + ' 9\n')
fr.close()
#Importing data
X_train, Y_train = image_preloader(TRAIN_DATA, image_shape=(56,56),mode='file', categorical_labels=True,normalize=True)
X_test, Y_test = image_preloader(TEST_DATA, image_shape=(56,56),mode='file', categorical_labels=True,normalize=True)
X_val, Y_val = image_preloader(VALIDATION_DATA, image_shape=(56,56),mode='file', categorical_labels=True,normalize=True)
print ("Dataset")
print ("Number of training images {}".format(len(X_train)))
print ("Number of testing images {}".format(len(X_test)))
print ("Number of validation images {}".format(len(X_val)))
print ("Shape of an image {}" .format(X_train[1].shape))
print ("Shape of label:{} ,number of classes: {}".format(Y_train[1].shape,len(Y_train[1])))
#Sample Image
plt.imshow(X_train[1])
plt.axis('off')
plt.title('Sample image with label {}'.format(Y_train[1]))
plt.show()
print(type(X_test))
#input image
x=tf.placeholder(tf.float32,shape=[None,56,56,3] , name='input_image')
#input class
y_=tf.placeholder(tf.float32,shape=[None, 10] , name='input_class')
input_layer=x
print("Hiiiiiiii No error till this point")
#convolutional layer 1 --convolution+RELU activation
conv_layer1=tflearn.layers.conv.conv_2d(input_layer, nb_filter=64, filter_size=5, strides=[1,1,1,1],
padding='same', activation='relu', regularizer="L2", name='conv_layer_1')
#2x2 max pooling layer
out_layer1=tflearn.layers.conv.max_pool_2d(conv_layer1, 10)
#second convolutional layer
conv_layer2=tflearn.layers.conv.conv_2d(out_layer1, nb_filter=128, filter_size=5, strides=[1,1,1,1],
padding='same', activation='relu', regularizer="L2", name='conv_layer_2')
out_layer2=tflearn.layers.conv.max_pool_2d(conv_layer2, 10)
# third convolutional layer
conv_layer3=tflearn.layers.conv.conv_2d(out_layer2, nb_filter=128, filter_size=5, strides=[1,1,1,1],
padding='same', activation='relu', regularizer="L2", name='conv_layer_2')
out_layer3=tflearn.layers.conv.max_pool_2d(conv_layer3, 10)
#fully connected layer1
fcl= tflearn.layers.core.fully_connected(out_layer3, 4096, activation='relu' , name='FCL-1')
fcl_dropout_1 = tflearn.layers.core.dropout(fcl, 0.8)
#fully connected layer2
fc2= tflearn.layers.core.fully_connected(fcl_dropout_1, 4096, activation='relu' , name='FCL-2')
fcl_dropout_2 = tflearn.layers.core.dropout(fc2, 0.8)
#softmax layer output
y_predicted = tflearn.layers.core.fully_connected(fcl_dropout_2, 10, activation='softmax', name='output')
#loss function
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y_predicted+np.exp(-10)), reduction_indices=[1]))
#optimiser -
train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)
#calculating accuracy of our model
correct_prediction = tf.equal(tf.argmax(y_predicted,1), tf.argmax(y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
# session parameters
sess = tf.InteractiveSession()
#initialising variables
init = tf.global_variables_initializer()
sess.run(init)
saver = tf.train.Saver()
save_path="C:/Users/kdeepshi/Desktop/PyforE/Face-Detection/mark2.ckpt"
g = tf.get_default_graph()
# every operations in our graph
[op.name for op in g.get_operations()]
epoch=5000
batch_size=20
previous_batch=0
for i in range(epoch):
#batch wise training
if previous_batch >= len(X_train) :
previous_batch=0
current_batch=previous_batch+batch_size
x_input=X_train[previous_batch:current_batch]
x_images=np.array(x_input)
x_images=np.reshape(x_images,[batch_size,56,56,3])
y_input=Y_train[previous_batch:current_batch]
y_label=np.reshape(y_input,[batch_size,10])
previous_batch=previous_batch+batch_size
_,loss=sess.run([train_step, cross_entropy], feed_dict={x: x_images,y_: y_label})
if i%500==0:
n=50 #number of test samples
X_test=np.array(X_test)
x_test_images=np.reshape(X_test[0:n],[n,56,56,3])
y_test_labels=np.reshape(Y_test[0:n],[n,10])
Accuracy=sess.run(accuracy,feed_dict={x: x_test_images ,y_: y_test_labels})
print("Iteration no :{} , Accuracy:{} , Loss : {}" .format(i,Accuracy,loss))
saver.save(sess, save_path, global_step = i)
elif i % 100 ==0:
print("Iteration no :{} Loss : {}" .format(i,loss))
x_input=X_val
x_images=np.reshape(x_input,[len(X_val),56,56,3])
y_input=Y_val
y_label=np.reshape(y_input,[len(Y_val),10])
Accuracy_validation=sess.run(accuracy,feed_dict={x: x_images ,y_: y_label})
Accuracy_validation=round(Accuracy_validation*100,2)
print("Accuracy in the validation dataset: {} %".format(Accuracy_validation))
Test_FOLDER = 'C:/Users/kdeepshi/Desktop/PyforE/Face-Detection/Test'
filenames_image = os.listdir(Test_FOLDER)
total=len(filenames_image)
print(total)
test_files=filenames_image[0: int(total)]
for filename in test_files:
marty=Image.open(Test_FOLDER+'/'+filename)
marty_resize=marty.resize((56,56),Image.ANTIALIAS)
marty_resize=np.array(marty_resize)
marty_test=marty_resize/np.max(marty_resize).astype(float)
marty_test=np.reshape(marty_test,[1,56,56,3])
c=sess.run(y_predicted, feed_dict={x: marty_test})
d= np.argmax(c)
#test your own images
#test_image=Image.open('/path to file')
#test_image= process_img(test_image)
#predicted_array= sess.run(y_predicted, feed_dict={x: test_image})
#predicted_class= np.argmax(predicted_array)
if d==0:
print("This is Mark\n")
elif d==1:
print("This is lucas\n")
elif d==2:
print("This is Ann")
elif d==3:
print("This is Henrry\n")
elif d==4:
print("This is Hanna\n")
elif d==5:
print("This is Jack")
elif d==6:
print("This is Harry\n")
elif d==7:
print("This is Lui")
elif d==8:
print("This is Karlos\n")
elif d==9:
print("This is guan\n")
这是错误:
C:\Users\kdeepshi\Desktop\PyforE\Face-Detection>multi.py
curses is not supported on this machine (please install/reinstall curses for an optimal experience)
Dataset
Number of training images 22
Number of testing images 6
Number of validation images 3
C:\ProgramData\Anaconda3\lib\site-packages\PIL\TiffImagePlugin.py:692: UserWarning: Possibly corrupt EXIF data. Expecting to read 12 bytes but only got 0. Skipping tag 270
"Skipping tag %s" % (size, len(data), tag))
C:\ProgramData\Anaconda3\lib\site-packages\PIL\TiffImagePlugin.py:692: UserWarning: Possibly corrupt EXIF data. Expecting to read 6 bytes but only got 0. Skipping tag 271
"Skipping tag %s" % (size, len(data), tag))
C:\ProgramData\Anaconda3\lib\site-packages\PIL\TiffImagePlugin.py:692: UserWarning: Possibly corrupt EXIF data. Expecting to read 8 bytes but only got 0. Skipping tag 272 "Skipping tag %s" % (size, len(data), tag))
C:\ProgramData\Anaconda3\lib\site-packages\PIL\TiffImagePlugin.py:692: UserWarning: Possibly corrupt EXIF data. Expecting to read 64 bytes but only got 0. Skipping tag 282 "Skipping tag %s" % (size, len(data), tag))
C:\ProgramData\Anaconda3\lib\site-packages\PIL\TiffImagePlugin.py:692: UserWarning: Possibly corrupt EXIF data. Expecting to read 64 bytes but only got 0. Skipping tag 283 "Skipping tag %s" % (size, len(data), tag))
C:\ProgramData\Anaconda3\lib\site-packages\PIL\TiffImagePlugin.py:692: UserWarning: Possibly corrupt EXIF data. Expecting to read 20 bytes but only got 0. Skipping tag 306 "Skipping tag %s" % (size, len(data), tag))
C:\ProgramData\Anaconda3\lib\site-packages\PIL\TiffImagePlugin.py:692: UserWarning: Possibly corrupt EXIF data. Expecting to read 24 bytes but only got 0. Skipping tag 529 "Skipping tag %s" % (size, len(data), tag))
C:\ProgramData\Anaconda3\lib\site-packages\PIL\TiffImagePlugin.py:692: UserWarning: Possibly corrupt EXIF data. Expecting to read 24 bytes but only got 0. Skipping tag 532 "Skipping tag %s" % (size, len(data), tag))
C:\ProgramData\Anaconda3\lib\site-packages\PIL\TiffImagePlugin.py:692: UserWarning: Possibly corrupt EXIF data. Expecting to read 40 bytes but only got 0. Skipping tag 33432 "Skipping tag %s" % (size, len(data), tag))
C:\ProgramData\Anaconda3\lib\site-packages\PIL\TiffImagePlugin.py:709: UserWarning: Corrupt EXIF data. Expecting to read 2 bytes but only got 0. warnings.warn(str(msg))
Shape of an image (56, 56, 3)
Shape of label:(10,) ,number of classes: 10
最佳答案
从 PIL 模块中的图像读取 EXIF 数据时出现问题。我倾向于认为这是 PIL 中的错误,而不是图像损坏。由于深度学习不需要这些数据,因此您只需清理文件即可。为此,请下载ExifTool并运行以下命令:
exiftool -r -all= -ext JPEG D:\datasets\ImageNet\train
-r
:递归-all
:将所有 EXIF 数据设置为空-ext
:文件扩展名
这适用于 WIndows 和 Linux。
关于python - "UserWarning: Possibly corrupt EXIF data"对图像进行分类时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46232981/
我用的是“tab10”调色板,因为它的颜色是蓝色、绿色、橙色和红色。。簇的数量只有4个,调色板“tab10”有4种以上的颜色。有没有办法解决这个用户警告问题?。输出为:
我用的是“tab10”调色板,因为它的颜色是蓝色、绿色、橙色和红色。。簇的数量只有4个,调色板“tab10”有4种以上的颜色。有没有办法解决这个用户警告问题?。输出为:
从 matplotlib 收到此警告,我尝试设置 fmt,但它对我不起作用(也许做错了)。我确实抑制了警告并且它起作用了,但我不想抑制所有 python 警告,因为我认为这应该可以解决。谢谢你的帮助。
我使用 openpyxl 来解析 .xlsm 文件,并使用 pytest 进行测试。 当我打开文件时,我得到: OpenPyxl -> UserWarning:不支持数据验证扩展,将被删除 这并不是真
我使用带有密码管理器的开启器,当我第一次使用我的开启器时,我收到了以下警告消息: /usr/lib/python2.7/urllib2.py:894: UserWarning: Basic Auth
运行命令 dataframe['geometry'].centroid显示警告: 列“几何”由多多边形对象组成。如何解决此问题以准确计算多多边形形状的质心? 最佳答案 这个错误可以通过投影来解决这个问
这个问题在这里已经有了答案: Python: UserWarning: This pattern has match groups. To actually get the groups, use
假设我有类似这样的代码: import pandas as pd df=pd.DataFrame({'Name': [ 'Jay Leno', 'JayLin', 'Jay-Jameson', 'Li
在命令行中运行大多数 python 脚本时会收到以下类型的警告: /Library/Python/2.6/site-packages/virtualenvwrapper/hook_loader.py:
安装 Google Cloud Bigquery 模块后,如果我将该模块导入 python 代码。我看到这条警告消息。在 python 3.7.3 Virtualenv 中发生在我身上。 尝试重新安装
当我用另一组数据屏蔽我的数据集时,它会显示用户警告: bool 系列键将被重新索引以匹配 DataFrame 索引。我该如何避免这种情况? Python 会自动重新索引它,但该列的标题是空白的,我似乎
我正在尝试学习 Python(第 2 天),并希望首先使用 Excel 书籍进行练习,因为这是我感到舒适/流利的地方。 在运行以下代码时,我立即遇到了一个我无法理解的错误: import openpy
尝试使用 python matplotlib 绘制图形:但不断收到以下警告消息: "UserWaring: tight_layout: falling back to Agg renderer wa
当我使用 pip 将东西安装到 virtualenv 中时,我经常看到消息“UserWarning: Unbuilt egg for setuptools”。我总是安全地忽略它并继续我的业务,它似
给定以下 pandas DataFrame - json_path报告组实体/分组实体 ID调整后值(value)(今天,无股息,美元)调整后的 TWR(当前季度,无股息,美元)调整后的 TWR(年初
我正在尝试运行来自 official website 的基本 matplotlib 示例: 但是,当我运行代码时,我的 Python 解释器会报错并输出以下消息: UserWarning: Matpl
我正在尝试运行来自 official website 的基本 matplotlib 示例: 但是,当我运行代码时,我的 Python 解释器会报错并输出以下消息: UserWarning: Matpl
在 pytest 中断言 UserWarning 和 SystemExit 在我的应用程序中,我有一个函数,当提供错误的参数值时,将从 warnings 模块中引发一个 UserWarnings,然后
下面是我的多图像分类代码。我收到错误;我认为这是因为加载和其他地方尺寸不匹配。 错误消息从代码结束处开始。有人能看出问题所在吗? #importing necessary packages impor
我有一个数据框,我尝试获取字符串,其中列中包含一些字符串Df 看起来像 member_id,event_path,event_time,event_duration 30595,"2016-03-30
我是一名优秀的程序员,十分优秀!