目标检测中遇到的问题和 docker导出日志

news/2024/6/3 18:58:57 标签: docker, 容器, 运维

一 docker容器导出日志

导出日志在Linux服务器的本地目录下,可以直接下载

docker logs 容器名称 > log.txt

二 Flask使用main执行

1 改dockerfile 文件内容

#CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"]
CMD [ "python", "./app.py" ]

2 改 app.py 中的内容

from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello():
    return "Hello, World!"

if __name__ == '__main__':
    app.run(host='0.0.0.0')

三 针对加载模型时间过长

将模型在主程序 main 中加载,进行flask交互时,将全局变量直接导入使用模块中,比如提前加载YOLOv5模型。

if __name__ == "__main__":
    os.makedirs("./config/", exist_ok=True)
    config = Config('config/config.json')

    print("加载YOLO模型:")
    # 从本地目录加载自定义的YOLOv5模型
    yolo_model = torch.hub.load('yolov5', 'custom', path='yolov5/best.pt', source='local')
    # 设置置信度阈值
    yolo_model.conf = config.floating_threshold
    app.run(host='0.0.0.0')

四 提取图片中的识别区,将无关部分去除

def adjust_img_size(img, width_ratio=1, height_ratio=0.8, padding_color=(255, 255, 255)):
    """
    获取图片中间长宽各1/2的中间区域,外部全部填充为指定颜色。

    Parameters:
        img (numpy.ndarray or PIL.Image.Image): 输入的图片,可以是numpy数组或PIL图像对象。
        padding_color (tuple): 填充的颜色,格式为 (R, G, B)。
        width_ratio:ratio
        height_ratio:ratio

    Returns:
        numpy.ndarray: 调整后的图片数组。
    """
    # 将输入图片转换为numpy数组
    if isinstance(img, Image.Image):
        img = np.array(img)

    # 获取图片尺寸
    height, width, channels = img.shape

    # 创建填充区域
    padding = np.full((height, width, channels), padding_color, dtype=np.uint8)

    # 计算截取的高度和宽度
    crop_height = int(height * height_ratio)
    crop_width = int(width * width_ratio)

    height_1 = int((height - crop_height)*0.5)
    width_1 = int((width - crop_width) * 0.5)

    # 截取图像
    cropped_image = img[height_1:crop_height + height_1, width_1:crop_width + width_1]

    # 将原始图片放入填充区域的中间
    padding[height_1:crop_height + height_1, width_1:crop_width + width_1] = cropped_image

    return padding

返回图片中固定比例的点

def get_point(img, height_ratio, width_ratio):
    """返回图片中的点目标点,用于在图上做标注"""
    # 获取图片尺寸
    height, width, channels = img.shape
    # print('查看形状:', img.shape)

    # 计算截取的高度和宽度
    crop_height = int(height * height_ratio)
    crop_width = int(width * width_ratio)

    height_1 = int((height - crop_height))
    width_1 = int((width - crop_width) * 0.5)

    width_2 = width - width_1
    height_2 = height - int((height - crop_height) * 0.5)
    # print('查看返回值:', width_1, height_1, width_2, height_2)

    return width_1, height_1, width_2, height_2


http://www.niftyadmin.cn/n/4929370.html

相关文章

谷歌推出Flax:JAX的神经网络库

在优化理论中,损失或成本函数测量拟合或预测值与实际值之间的距离。对于大多数机器学习模型,提高性能意味着最小化损失函数。 但对于深度神经网络,执行梯度下降以最小化每个参数的损失函数可能会消耗大量资源。传统方法包括手动推导和编码&a…

数据结构:交换排序

冒泡排序 起泡排序,别名“冒泡排序”,该算法的核心思想是将无序表中的所有记录,通过两两比较关键字,得出升序序列或者降序序列。 算法步骤 比较相邻的元素。如果第一个元素大于第二个元素,就交换它们。对每一对相邻…

【人工智能概述】python妙用 __str__()

【人工智能概述】python妙用 str() 文章目录 【人工智能概述】python妙用 __str__()一.python内置函数__str__() 一.python内置函数__str__() 通过自定义__str__()函数可以打印对象中相关的内容。 class Person(object):def __init__(self, name tom, age 10):self.name n…

PHP 之房贷计算器、组合贷

一、等额本金 // (等额本金) //$loanAmount>贷款金额 //$loanPeriod>贷款年限 //$interestRate>贷款利息 function calculateEqualPrincipalPayment($loanAmount, $loanPeriod, $interestRate) {$monthlyPrincipal $loanAmount / ($loanPerio…

【算法】逆波兰表达式

文章目录 定义求法代码思想: 定义 逆波兰表达式也称为“后缀表达式”,是将运算符写在操作数之后的运算式。 求法 *如:(ab)c-(ab)/e的转换过程: 先加上所有的括号。 (((ab)*c)-((ab)/e))将所有的运算符移到括号外面 (((ab) c)* …

用C++实现的RTS游戏的路径查找算法(A*、JPS、Wall-tracing)

在实时策略(RTS)游戏中,路径查找是一个关键的问题。游戏中的单位需要能够找到从一个地方到另一个地方的最佳路径。这个问题在计算机科学中被广泛研究,有许多已经存在的算法可以解决这个问题。在本文中,我们将探讨三种在…

使用xrdp协议远程桌面控制树莓派,无需公网IP!

远程桌面控制树莓派,我们可以用xrdp协议来实现,它内部使用的是windows远程桌面的协议。我们只需要在树莓派上安装xrdp,就可以在同个局域网下远程桌面控制树莓派。 而如果需要在公网下远程桌面控制树莓派,可以通过cpolar内网穿透&…

Linux MQTT智能家居项目(智能家居界面布局)

文章目录 前言一、创建工程项目二、界面布局准备工作三、正式界面布局总结 前言 一、创建工程项目 1.选择工程名称和项目保存路径 2.选择QWidget 3.添加保存图片的资源文件: 在工程目录下添加Icon文件夹保存图片: 将文件放入目录中: …