yanwencai001 2019-05-23 11:03 采纳率: 0%
浏览 13995

TypeError: expected str, bytes or os.PathLike object, not tuple此报错有大神遇到过吗怎么解决

import gensim
import torch
from util import read_caption_data, char_table_to_sentence, word2vec
from torch.utils.serialization import load_lua
import os

def save_embeddings(filepath, filename, embeddings):
if not os.path.exists(filepath):
os.mkdir(filepath)
target_path = os.path.join(filepath, filename)
torch.save({'embeds': embeddings}, target_path) # 保存整个网络,包括整个计算图
return True

class Word_Embeddings():

def __init__(self, root_dir, caption_dir, split_file, alphabet):
    self.caption_dir = caption_dir
    self.split_file = split_file
    self.alphabet = alphabet

    self.dir_path = os.path.join(root_dir, 'pretrained_embeddings')

    self.model = gensim.models.KeyedVectors.load_word2vec_format('/data0/Masters/yanwencai/CrossModalRetrieval-master/models/GoogleNews-vectors-negative300.bin',
                                                                 binary=True)           #加载Google训练的词向量

def load_caption(self, cap):
    assert (os.path.isfile(cap))

    cls, fn = cap.split('/')[-2], cap.split('/')[-1]
    file_path = os.path.join((self.dir_path, cls)) #报错行

    caption = load_lua(cap)
    char = caption['char']

    sentence = char_table_to_sentence(self.alphabet, char)

    embeds = word2vec(self.model, sentence, sen_size=16, emb_size=300)

    return file_path, fn, embeds

alphabet = "abcdefghijklmnopqrstuvwxyz0123456789-,;.!?:'\"/\|_@#$%^&*~`+-=<>()[]{} "

data_dir = '/data0/Masters/yanwencai/CrossModalRetrieval-master/datasets/CUB_200_2011/'

split_file = os.path.join(data_dir, 'train_val.txt')

caption_dir = os.path.join(data_dir, 'cub_icml')

caption_list = read_caption_data(caption_dir, split_file)

WE = Word_Embeddings(data_dir, caption_dir, split_file, alphabet)

for idx, cap in enumerate(caption_list):
filepath, fn, embeds = WE.load_caption(cap) #报错行
if save_embeddings(filepath, fn, embeds):
print(filepath, fn, 'saved')


错误描述:Traceback (most recent call last):
  File "word_embeddings.py", line 61, in <module>
    filepath, fn, embeds,type = WE.load_caption(cap)
  File "word_embeddings.py", line 36, in load_caption
    file_path,type = os.path.join((self.dir_path, cls))
  File "/home/amax/anaconda2/lib/python3.6/posixpath.py", line 80, in join
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not tuple
请各位大神帮忙看一下,xie'xie
  • 写回答

2条回答 默认 最新

  • 黄嘻嘻 2020-08-18 10:15
    关注

    你是不是在文件路径后面多写了一个逗号?

    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?