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

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
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集