category.php?catid=379&areaid=10785&streetid=4677如何写伪静态


来源: 【铭竟科技】  日期:2023-06-28 12:34:44  点击:307  属于:常见问题
category.php?catid=379&areaid=10785&streetid=4677如何写伪静态
详细介绍:

tags:

篇首语:主要介绍了category.php?catid=379&areaid=10785&streetid=4677如何写伪静态相关的知识,希望对你有一定的参考价值。

category.php?catid=379&areaid=10785&streetid=4677如何写伪静态

 

 

楼主,如果你调用的是地区,出来数字,那可能是用错了变量,调用出了地区id ,areaid。

地区有缓存,可以根据程序返回的id去调用缓存。

$AREA[$areaid][name]

areaid替换成你调用地区的变量

 

 

参考技术A

 

 

显示地区名称用$AREA[$areaid][name]就行了.

或许程序中间$areaid变量有被重定义的情况.仔细检查一下$areaid 是否

为正确期望值.可以echo $areaid;看一下.

 

 

参考技术B1、方法有开启rewrite干,正则表达匹配。这种用的应该不多。

2、用框架路由实现。
laravel
$router->get('/category/catid/areaid/streetid', function()
return ""
);
3、不用框架
开启rewrite,所有访问都路由到一个php 上,比如index.php
RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
然后根据全局函数,获取访问路径。
category/catid/379/areaid/10785/streetid/4677
$param=$_SERVER['REQUEST_URI']
然后根据“/”转数组。
$param的值差不多这个样子['category','catid','379','areaid','10785','streetid','4677']
然后设计算法,执行category.php 。大多框架的路由 基本上也差不多这个思路。

 

完美解决错误:in bbox2out catid = (clsid2catid[int(clsid)]) KeyError:

 

最近用了一下paddlepaddle深度学习框架训练了一下目标检测模型,然后在训练一段时候后在验证的时候出现了错误:

File "...PaddleDetection-masterppdetutilscoco_.py", line 318, in bbox2out
    catid = (clsid2catid[int(clsid)])
KeyError: 6

小编是训练一个目标检测的模型, KeyError: 6 中的6是要检测的类别的数量(6个类别)。

遇到这个错误的时候,很多人可能要放弃了(这框架我不玩了

其实产生这个错误的原因就是paddle在验证的时候没有可虑到不同数据的问题,也就是说这个代码在coco数据集上训练可能是完全没有问题,那么怎样才能训练自己的数据呢?

首先找到报错的文件 File "...PaddleDetection-masterppdetutilscoco_.py",这个文件是目标检测文件的位置,每个人可能放置的位置不一样,因人而异,找到你的文件夹的对应的文件,即可。

然后小编找到了报错的位置,对报错的内容进行了输出,发现是代码的bug(不兼容),

报错的函数:

def bbox2out(results, clsid2catid, is_bbox_normalized=False):
    """
    Args:
        results: request a dict, should include: `bbox`, `im_id`,
                 if is_bbox_normalized=True, also need `im_shape`.
        clsid2catid: class id to category id map of COCO2017 dataset.
        is_bbox_normalized: whether or not bbox is normalized.
    """
    
    xywh_res = []
    for t in results:
        bboxes = t['bbox'][0]
        if len(t['bbox'][1]) == 0: continue
        lengths = t['bbox'][1][0]
        im_ids = np.array(t['im_id'][0]).flatten()
        if bboxes.shape == (1, 1) or bboxes is None or len(bboxes) == 0:
            continue

        k = 0
        for i in range(len(lengths)):
            num = lengths[i]
            im_id = int(im_ids[i])
            for j in range(num):
                dt = bboxes[k]
                clsid, score, xmin, ymin, xmax, ymax = dt.tolist()
                if clsid < 0: continue
                
                catid = (clsid2catid[int(clsid)])

                if is_bbox_normalized:
                    xmin, ymin, xmax, ymax = 
                            clip_bbox([xmin, ymin, xmax, ymax])
                    w = xmax - xmin
                    h = ymax - ymin
                    im_shape = t['im_shape'][0][i].tolist()
                    im_height, im_width = int(im_shape[0]), int(im_shape[1])
                    xmin *= im_width
                    ymin *= im_height
                    w *= im_width
                    h *= im_height
                else:
                    # for yolov4
                    # w = xmax - xmin
                    # h = ymax - ymin
                    w = xmax - xmin + 1
                    h = ymax - ymin + 1

                bbox = [xmin, ymin, w, h]
                coco_res = {
                    'image_id': im_id,
                    'category_id': catid,
                    'bbox': bbox,
                    'score': score
                }
                xywh_res.append(coco_res)
                k += 1
    return xywh_res

我们看下函数的注释,说明了是用于coco数据集,那么我们的假的coco数据集可能就不兼容

后来小编通过自己编写代码完美修改了数据集标注的格式,模型训练就不会再产生问题了。

 

以上是关于category.php?catid=379&areaid=10785&streetid=4677如何写伪静态的主要内容,如果未能解决你的问题,请参考以下文章