尝试使用 detector 训练对象检测模型并在数据集中出现 CV2 错误
我正在使用 detector 和 Google Colab Notebook 来训练和测试我的数据集。我使用 google 和 labelImg 的图像下载器从我的图像创建 .xml 文件。我将它们存储在我的驱动器中的 object_detection 文件夹中。我收到以下错误:
Epoch 1 of 25
Begin iterating over training dataset
68%|██████▊ | 75/111 [02:03<00:59, 1.64s/it]
---------------------------------------------------------------------------
error Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/detecto/utils.py in read_image(path)
137 try:
--> 138 rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
139 except cv2.error as e:
error: OpenCV(4.1.2) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
8 frames
/usr/local/lib/python3.7/dist-packages/detecto/utils.py in read_image(path)
138 rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
139 except cv2.error as e:
--> 140 raise ValueError(f'Could not convert image color: {str(e)}')
141
142 return rgb_image
ValueError: Could not convert image color: OpenCV(4.1.2) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'
这是我当前拥有的代码:_________________________
import torch
print(torch.cuda.is_available())
print(torch.cuda.get_device_name(0))
from detecto import core, utils, visualize
import numpy as np
import seaborn as sns
import torchvision.transforms as tf
from detecto.visualize import show_labeled_image, plot_prediction_grid
custom_transforms = tf.Compose([
tf.ToPILImage(),
tf.Resize(900),
tf.RandomHorizontalFlip(0.5),
tf.ColorJitter(saturation=0.2),
tf.ToTensor(),
utils.normalize_transform(),
])
dataset = core.Dataset('images/', transform = custom_transforms)
loader=core.DataLoader(dataset, batch_size=2, shuffle=True)
model = core.Model(['Card', 'Card Name'])
losses = model.fit(loader, dataset, epochs=25, lr_step_size=5, learning_rate= 0.001, verbose=True)
或者,我也尝试过:
import torch
print(torch.cuda.is_available())
print(torch.cuda.get_device_name(0))
from detecto import core, utils, visualize
import numpy as np
from detecto.visualize import show_labeled_image, plot_prediction_grid
dataset = core.Dataset('images/')
model = core.Model(['Card', 'Card Name'])
model.fit(dataset)
请帮助我解决此问题。
I am using detecto and Google Colab Notebook to train and test my dataset. I used an image downloader off google and labelImg to create .xml files from my images. I am storing them in my drive in an object_detection folder. I am getting the below error:
Epoch 1 of 25
Begin iterating over training dataset
68%|██████▊ | 75/111 [02:03<00:59, 1.64s/it]
---------------------------------------------------------------------------
error Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/detecto/utils.py in read_image(path)
137 try:
--> 138 rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
139 except cv2.error as e:
error: OpenCV(4.1.2) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
8 frames
/usr/local/lib/python3.7/dist-packages/detecto/utils.py in read_image(path)
138 rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
139 except cv2.error as e:
--> 140 raise ValueError(f'Could not convert image color: {str(e)}')
141
142 return rgb_image
ValueError: Could not convert image color: OpenCV(4.1.2) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'
This is the code that I currently have:_________________________
import torch
print(torch.cuda.is_available())
print(torch.cuda.get_device_name(0))
from detecto import core, utils, visualize
import numpy as np
import seaborn as sns
import torchvision.transforms as tf
from detecto.visualize import show_labeled_image, plot_prediction_grid
custom_transforms = tf.Compose([
tf.ToPILImage(),
tf.Resize(900),
tf.RandomHorizontalFlip(0.5),
tf.ColorJitter(saturation=0.2),
tf.ToTensor(),
utils.normalize_transform(),
])
dataset = core.Dataset('images/', transform = custom_transforms)
loader=core.DataLoader(dataset, batch_size=2, shuffle=True)
model = core.Model(['Card', 'Card Name'])
losses = model.fit(loader, dataset, epochs=25, lr_step_size=5, learning_rate= 0.001, verbose=True)
Alternatively, I also tried:
import torch
print(torch.cuda.is_available())
print(torch.cuda.get_device_name(0))
from detecto import core, utils, visualize
import numpy as np
from detecto.visualize import show_labeled_image, plot_prediction_grid
dataset = core.Dataset('images/')
model = core.Model(['Card', 'Card Name'])
model.fit(dataset)
Please help me fix this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我尝试使用包含 30 张图像的较小数据集来训练模型,结果发现 .gif 图像意外出现在我的数据集中并且无法读取。确保数据集中没有 .gif 文件,如果出现此错误,请使用较小的测试集。
I tried working with a smaller dataset of 30 images to train the model and figured out that a .gif image was accidentally in my dataset and unable to be read. Make sure there are no .gif files in the dataset and use a smaller test set if you get this error.