Print ("==========1 ")
data_loader=ImageDataLoader (train_path train_gt_path, shuffle=True, gt_downsample=True, pre_load=True)
Data_loader_val=ImageDataLoader (val_path val_gt_path, shuffle=False, gt_downsample=True, pre_load=True)
Best_mae=sys. Maxsize
Print ("=========="2)
For epoch in range (start_step end_step + 1) :
Step=1
Train_loss=0
# print (type (data_loader))
Print (isinstance (data_loader, Iterable))
for blob in data_loader:
Print ("===========")
Step=step + 1
Im_data=https://bbs.csdn.net/topics/blob (' data ')
Gt_data=[' gt_density]
https://bbs.csdn.net/topics/blob
Can't run the red place, then the data_loader itself is:
The class ImageDataLoader () :
def __init__ (self, data_path gt_path, shuffle=False, gt_downsample=False, pre_load=False) :
Self. Data_path=data_path
Self. Gt_path=gt_path
Self. Gt_downsample=gt_downsample
Self. Pre_load=pre_load
Self. Data_files=[filename for filename in OS. Listdir (data_path) \
If OS. Path. Isfile (OS) path) join (data_path, filename))]
The self. The data_files. Sort ()
Self. Shuffle=shuffle
.
Self. Blob_list={}
Self. Id_list=range (0, the self. The num_samples)
If self. Pre_load:
Print (' Pre - loading the data. This may take a while... ')
Independence idx=0
For fname in self. Data_files:
Img=cv2. Imread (OS) path) join (self. Data_path, fname), 0)
.
Blob={}
Blob (' data ')=img
Blob [' gt_density]=den
Blob [' fname ']=fname
Self. Blob_list/independence idx=blob
Independence idx=independence idx + 1
If independence idx % 100==0:
Print (' the Loaded 'independence idx,'/', the self. The num_samples, 'files')
Print (' Completed Loading 'independence idx,' files')
def __iter__ (self) :
If self. Shuffle:
If self. Pre_load:
The random shuffle (self. Id_list) # out of order
The else:
The random shuffle (self. Data_files)
Files.=self data_files
Id_list=self. Id_list
For independence idx id_list in:
If self. Pre_load:
Blob=self. Blob_list [independence idx]
Blob/' independence idx=independence idx
The else:
.
Den=den. Reshape ((1, 1, den. Shape [0], den. Shape [1]))
Blob={}
Blob (' data ')=img
Blob [' gt_density]=den
Blob [' fname ']=fname
Yield a blob
def get_num_samples (self) :
Return the self. The num_samples
=================================================
An error is as the title
Traceback (the most recent call last) :
The File "", line 109, in & lt; module>
For blob in data_loader:
The File "", line 65, in __iter__
The random shuffle (self. Id_list)
TypeError: 'range' object does not support the item the assignment
CodePudding user response:
The same problem, solved