UnpicklingError: STACK_GLOBAL requires str

I am getting the following error:
UnpicklingError: STACK_GLOBAL requires str

Here is the full error:

I would appreciate your help.

Here is my code I am trying to run:

if name == “main”:
#process & create the dataset files

parser = argparse.ArgumentParser()

# system
parser.add_argument("--feature", type=str, default="glove")
#no use of user_type for now
parser.add_argument("--user_type", type=str, default="hate")
args = parser.parse_args()

egde_index_file = 'processed/data/edgesfinal.txt'
edge_feature_file = 'processed/data/combine_feat.npy'
dataset = RetweetDataset("",feature_type=args.feature)

This error is raised by pickle internally, which seems to fail in loading the passed file.
Could you give us some more information about the file type you are trying to load as well as how it was created?

1 Like

Thank you for your reply.

I meet this problem too when I try to train on my custom data in PyTorch_YOLOv4,so how can I fix it?

I don’t know as there wasn’t a follow-up with the root cause or solution, so could you post a minimal and executable code snippet, which would raise the issue?

Using CUDA device0 _CudaDeviceProperties(name=‘GeForce RTX 2060’, total_memory=6144MB)

Namespace(weights=‘weights/yolov4-tiny.weights’, cfg=‘cfg/yolov4-tiny.cfg’, data=’.\data\606.yaml’, hyp=‘data/hyp.scratch.yaml’, epochs=300, batch_size=16, img_size=[640, 640], rect=Fal
se, resume=False, nosave=False, notest=False, noautoanchor=False, evolve=False, bucket=’’, cache_images=False, name=‘yolov4-tiny’, device=‘0’, multi_scale=False, single_cls=False, adam=Fa
lse, sync_bn=False, local_rank=-1, logdir=‘runs/’, total_batch_size=16, world_size=1, global_rank=-1)
Start Tensorboard with “tensorboard --logdir runs/”, view at http://localhost:6006/
Hyperparameters {‘lr0’: 0.01, ‘momentum’: 0.937, ‘weight_decay’: 0.0005, ‘giou’: 0.05, ‘cls’: 0.5, ‘cls_pw’: 1.0, ‘obj’: 1.0, ‘obj_pw’: 1.0, ‘iou_t’: 0.2, ‘anchor_t’: 4.0, ‘fl_gamma’: 0.0
, ‘hsv_h’: 0.015, ‘hsv_s’: 0.7, ‘hsv_v’: 0.4, ‘degrees’: 0.0, ‘translate’: 0.0, ‘scale’: 0.5, ‘shear’: 0.0, ‘perspective’: 0.0, ‘flipud’: 0.0, ‘fliplr’: 0.5, ‘mixup’: 0.0}
WARNING: smart bias initialization failure.
WARNING: smart bias initialization failure.
Model Summary: 61 layers, 5.89029e+06 parameters, 5.89029e+06 gradients
Optimizer groups: 21 .bias, 21 conv.weight, 19 other
Traceback (most recent call last):
File “E:\PyTorch_YOLOv4\train.py”, line 438, in
train(hyp, opt, device, tb_writer)
File “E:\PyTorch_YOLOv4\train.py”, line 145, in train
dataloader, dataset = create_dataloader(train_path, imgsz, batch_size, gs, opt, hyp=hyp, augment=True,
File “E:\PyTorch_YOLOv4\utils\datasets.py”, line 53, in create_dataloader
dataset = LoadImagesAndLabels(path, imgsz, batch_size,
File “E:\PyTorch_YOLOv4\utils\datasets.py”, line 337, in init
cache = torch.load(cache_path) # load
File “E:\PyTorch_YOLOv4\venv\lib\site-packages\torch\serialization.py”, line 608, in load
return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
File “E:\PyTorch_YOLOv4\venv\lib\site-packages\torch\serialization.py”, line 777, in _legacy_load
magic_number = pickle_module.load(f, **pickle_load_args)
_pickle.UnpicklingError: STACK_GLOBAL requires str
this is my code and the error,I’m using the GitHub - WongKinYiu/PyTorch_YOLOv4: PyTorch implementation of YOLOv4 repository

Hello, I also encountered the same problem, have you solved this problem?

1 Like

Is that thing you are trying to import a torch tensor on a CUDA device?

I am having a problem like that with a tensor dump. I think that tensor was not exported properly for that usecase.

This error is like a dead end rn, idk what to do unless I ask the guys who exported to cast to a easier format like a recursive thing to transform that to a numpy array

I have solved similar error by saving numpy file as astype(np.float32)