0

I had run the traditional CRSNet structure code:

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

While what I have now is another dataset which directly consist of one single h5py for test and one for train, this existing codes for CRSNet seems to be separating all existing images. May I know is there ano method to use other dataset on this piece of code? Thanks

CodingKingggg
  • 73
  • 1
  • 10
  • The short answer is yes. But you will have to adapt your code to read the train and test files, then reformat to be what CRSNet expects. This is more than Python/h5py code. You also need to understand the CRSNet schema, and the schema of the train and test files. – kcw78 Apr 09 '21 at 14:22
  • @kcw78 Thanks. I understand and run the original CRSNet once. Yet when it goes to the dataset I have, I don't have any idea on that. As the dataset I am having is in h5 with two keys, would you tell me any step to know how to start with please. Thanks a lot for your help – CodingKingggg Apr 09 '21 at 16:44
  • Is this related to your other post about extracting density_maps data to separate files (1 for each image)? [Extracting datasets from 1 HDF5 file to multiple files](https://stackoverflow.com/q/67018509/10462884). If not, please clarify what you want to do here. – kcw78 Apr 09 '21 at 20:29
  • @kcw78 Sorry to misleading. My question is actually in the same set of problems. Just that I am quite confuse in what I doing right now. I will summarise and make the edit later one. Thanks a lot. – CodingKingggg Apr 10 '21 at 02:42

0 Answers0