首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用于Tensorflow对象检测模型的理想图像大小是多少?

用于Tensorflow对象检测模型的理想图像大小是多少?
EN

Stack Overflow用户
提问于 2022-05-11 04:48:23
回答 1查看 116关注 0票数 0

我正在使用TFOD创建一个对象检测模型。我必须在我的image.What中检测一个非常小的对象,这应该是输入到我的模型中的图像的理想大小吗?我的一些图像非常大。

另外,我已经给一些图片贴上了标签。我也可以调整这些图像的大小吗?还是我得再给他们贴上标签?

EN

回答 1

Stack Overflow用户

发布于 2022-05-11 08:16:17

当你做图像识别,你不期望他们有100%的正确,类似于输入图像或VDO输入,但对齐或后定位。

这不是最后的结果,我这样做只是为了好玩,但你可以看到,100%类似的培训输入与小数据集是不提供准确性的魅力图片。

样本

代码语言:javascript
运行
复制
import os
from os.path import exists

import tensorflow as tf

import cv2
import matplotlib.pyplot as plt
import matplotlib.animation as animation

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
None
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
physical_devices = tf.config.experimental.list_physical_devices('GPU')
assert len(physical_devices) > 0, "Not enough GPU hardware devices available"
config = tf.config.experimental.set_memory_growth(physical_devices[0], True)
print(physical_devices)
print(config)

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
: Variables
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
path_1 = "F:\\datasets\\downloads\\Duck_Shoe_2\\Duck\\"

list_picture = []
list_actual_picture = []
list_label = []
list_actual_label = ['None', 'Duck']

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
: Model Initialize
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
model = tf.keras.models.Sequential([
    tf.keras.layers.InputLayer(input_shape=( 29, 39, 3 )),
    tf.keras.layers.Conv2D(32, (3, 3), activation='relu'),
    tf.keras.layers.MaxPooling2D((2, 2)),
    tf.keras.layers.Reshape((234, 32)),
    tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(32, return_sequences=True, return_state=False)),
    tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(32)),
])
        
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(64))
model.add(tf.keras.layers.Dense(2))
model.summary()

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
: DataSet
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
for file in os.listdir( path_1 ):
    image = plt.imread( path_1 + file )
    list_actual_picture.append( image )
    image = tf.image.resize(image, [29, 39]).numpy()
    list_picture.append( image )
    list_label.append( 1 )
    
list_picture = tf.cast( list_picture, dtype=tf.int64 )
list_picture = tf.constant( list_picture, shape=( 6, 1, 29, 39, 3 ) )
list_label = tf.cast( list_label, dtype=tf.int64 )
list_label = tf.constant( list_label, shape=( 6, 1, 1, 1 ) )
dataset = tf.data.Dataset.from_tensor_slices(( list_picture, list_label ))
list_picture = tf.constant( list_picture, shape=( 6, 29, 39, 3 ) )

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
: Optimizer
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
optimizer = tf.keras.optimizers.Nadam( learning_rate=0.0001, beta_1=0.9, beta_2=0.999, epsilon=1e-07, name='Nadam' )

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
: Loss Fn
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""                               
lossfn = tf.keras.losses.MeanSquaredLogarithmicError(reduction=tf.keras.losses.Reduction.AUTO, name='mean_squared_logarithmic_error')

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
: Model Summary
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
model.compile(optimizer=optimizer, loss=lossfn, metrics=['accuracy'])

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
: Training
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
history = model.fit(dataset, epochs=3 ,validation_data=(dataset))



plt.figure(figsize=(3,2))
plt.title("Actors recognitions")
for i in range(len(list_picture)):
    img = tf.keras.preprocessing.image.array_to_img(
        list_picture[i],
        data_format=None,
        scale=True
    )
    img_array = tf.keras.preprocessing.image.img_to_array(img)
    img_array = tf.expand_dims(img_array, 0)
    predictions = model.predict(img_array)
    score = tf.nn.softmax(predictions[0])
    plt.subplot(3, 2, i + 1)
    plt.xticks([])
    plt.yticks([])
    plt.grid(False)
    plt.imshow(list_actual_picture[i])
    plt.xlabel(str(round(score[tf.math.argmax(score).numpy()].numpy(), 2)) + ":" +  str(list_actual_label[tf.math.argmax(score)]))
    
plt.show()

input('...')

输出

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72195548

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档