Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Computer vision 使用另一个数据集生成CRSNet_Computer Vision_Dataset_H5py - Fatal编程技术网

Computer vision 使用另一个数据集生成CRSNet

Computer vision 使用另一个数据集生成CRSNet,computer-vision,dataset,h5py,Computer Vision,Dataset,H5py,我运行了传统的CRSNet结构代码: import random import os from PIL import Image,ImageFilter,ImageDraw import numpy as np import h5py from PIL import ImageStat import cv2 def load_data(img_path,train = True): gt_path = img_path.replace('.jpg','.h5').replace('im

我运行了传统的CRSNet结构代码:

import random
import os
from PIL import Image,ImageFilter,ImageDraw
import numpy as np
import h5py
from PIL import ImageStat
import cv2

def load_data(img_path,train = True):
    gt_path = img_path.replace('.jpg','.h5').replace('images','ground_truth')
    img = Image.open(img_path).convert('RGB')
    gt_file = h5py.File(gt_path, 'r')
    target = np.asarray(gt_file['density'])
    print (target.shape)
    if False:
        crop_size = (img.size[0]/2,img.size[1]/2)
        if random.randint(0,9)<= -1:
            
            
            dx = int(random.randint(0,1)*img.size[0]*1./2)
            dy = int(random.randint(0,1)*img.size[1]*1./2)
        else:
            dx = int(random.random()*img.size[0]*1./2)
            dy = int(random.random()*img.size[1]*1./2)
        
        
        
        img = img.crop((dx,dy,crop_size[0]+dx,crop_size[1]+dy))
        target = target[dy:crop_size[1]+dy,dx:crop_size[0]+dx]
        
        
        
        
        if random.random()>0.8:
            target = np.fliplr(target)
            img = img.transpose(Image.FLIP_LEFT_RIGHT)
    
    
    
    
    target = cv2.resize((target),(target.shape[1]//8,target.shape[0]//8),interpolation = cv2.INTER_CUBIC)*64
    
    
    return img,target
随机导入
导入操作系统
从PIL导入图像、ImageFilter、ImageDraw
将numpy作为np导入
进口h5py
从PIL导入ImageStat
进口cv2
def加载数据(img\U路径,列车=真):
gt_path=img_path.replace('.jpg','.h5')。replace('images','ground_truth'))
img=Image.open(img\u路径).convert('RGB'))
gt_file=h5py.file(gt_路径'r')
target=np.asarray(gt_文件['density'])
打印(target.shape)
如果为假:
裁剪尺寸=(img.size[0]/2,img.size[1]/2)
如果随机。randint(0,9)0.8:
目标=np.fliplr(目标)
img=img.transpose(Image.FLIP\u LEFT\u RIGHT)
target=cv2.resize((target),(target.shape[1]//8,target.shape[0]//8),interpolation=cv2.INTER_CUBIC)*64
返回img,目标

虽然我现在拥有的是另一个数据集,它直接由一个用于测试的h5py和一个用于训练的h5py组成,但CRSNet的现有代码似乎将所有现有图像分离开来。我可以知道在这段代码中是否有使用其他数据集的方法吗?谢谢

简短的回答是肯定的。但您必须调整代码以读取列车和测试文件,然后重新格式化为CRSNet所期望的格式。这不仅仅是Python/h5py代码。您还需要了解CRSNet模式以及训练和测试文件的模式。@kcw78谢谢。我了解并运行过原始的CRSNet一次。然而,当它进入我拥有的数据集时,我对此一无所知。由于我拥有的数据集是h5中的两个键,请告诉我如何开始的步骤。非常感谢您的帮助。这与您的另一篇关于将密度图数据提取到单独文件(每个图像1个)的帖子有关吗。如果没有,请澄清您想在此处执行的操作。@kcw78抱歉误导您。我的问题实际上是在同一组问题中。只是我对我现在所做的感到困惑。我将在稍后进行总结和编辑。谢谢。