第一种方法(失败啦)
创建环境:
conda create -n pytorch04 python=3.6
使用下面的创建命令创建失败,不知道为啥。
conda create -n pytorch04 python=3.6 -i https://pypi.douban.com/simple/
激活环境:
activate pytorch04
进入程序所在位置:
cd E:\show attend and tell\a-PyTorch-Tutorial-to-Image-Captioning-master
运行create_input_files.py
python create_input_files.py
运行失败报错:
ModuleNotFoundError: No module named 'h5py'
安装h5py
pip install h5py -i https://pypi.douban.com/simple/
安装结果为:
Successfully installed cached-property-1.5.2 h5py-3.1.0
继续运行程序
python create_input_files.py
运行失败报错:
Traceback (most recent call last):
File "create_input_files.py", line 1, in <mo
from utils import create_input_files
File "E:\show attend and tell\a-PyTorch-Tuto
ils.py", line 5, in <module>
import torch
ModuleNotFoundError: No module named 'torch'
即环境中没有安装0.4版本的pytorch(github中原作者提示使用的是0.4版本的pytorch和3.6的python) 下一步安装0.4的pytorch
pip install http://download.pytorch.org/whl/cpu/torch-0.4.0-cp36-cp36m-win_amd64.whl
安装命令参考:Windows下安装PyTorch0.4.0
再次运行程序试试,出错:
Traceback (most recent call last):
File "create_input_files.py", line 1, in <modul
from utils import create_input_files
File "E:\show attend and tell\a-PyTorch-Tutoria
ils.py", line 5, in <module>
import torch
File "D:\python3\envs\pytorch04\lib\site-packag
in <module>
from torch._C import *
ImportError: DLL load failed: 找不到指定的模块。
网上查找解决方法之后使用(评论中该方法绝佳!)
conda install numpy pyyaml mkl cmake cffi
参考:from torch._C import * ImportError: DLL load failed: 找不到指定的模块。 输入python,再enter回车 输入import torch 没有报错,即表示导入torch不成功的问题已经解决,以上链接牛逼! 试试运行程序: python create_input_files.py 结果为:
Traceback (most recent call last):
File "create_input_files.py", line 1, in <
from utils import create_input_files
File "E:\show attend and tell\a-PyTorch-Tu
ils.py", line 6, in <module>
from scipy.misc import imread, imresize
ModuleNotFoundError: No module named 'scipy'
使用:
pip install scipy
安装结果为:
Installing collected packages: scipy
ERROR: pip's dependency resolver does not currently take into account all the pa
ckages that are installed. This behaviour is the source of the following depende
ncy conflicts.
parl 1.3.2 requires click, which is not installed.
parl 1.3.2 requires flask-cors, which is not installed.
parl 1.3.2 requires psutil>=5.6.2, which is not installed.
parl 1.3.2 requires pyarrow==0.13.0, which is not installed.
parl 1.3.2 requires pyzmq==18.0.1, which is not installed.
parl 1.3.2 requires tb-nightly==1.15.0a20190801, which is not installed.
parl 1.3.2 requires termcolor>=1.1.0, which is not installed.
Successfully installed scipy-1.5.4
ERROR部分是红色,即除第一行和最后一行不显示红色,其余均为红色 方法参考网上:ModuleNotFoundError: No module named 'scipy’解决方法
再运行程序,报错:
Traceback (most recent call last):
File "create_input_files.py", line 1, in <module>
from utils import create_input_files
File "E:\show attend and tell\a-PyTorch-Tutorial-to-Image-Captioning-master\ut
ils.py", line 6, in <module>
from scipy.misc import imread, imresize
ImportError: cannot import name 'imread'
查看scipy版本:
(pytorch04) E:\show attend and tell\a-PyTorch-Tutorial-to-Image-Captioning-maste
r>python
Python 3.6.13 |Anaconda, Inc.| (default, Mar 16 2021, 11:37:27) [MSC v.1916 64 b
it (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy
>>> print(scipy.__version__)
1.5.4
>>>
安装较低版本1.2.0的scipy
Requirement already satisfied: numpy>=1.8.2 in c:\users\admin\appdata\roaming\py
thon\python36\site-packages (from scipy==1.2.0) (1.19.5)
Installing collected packages: scipy
Attempting uninstall: scipy
Found existing installation: scipy 1.5.4
Uninstalling scipy-1.5.4:
Successfully uninstalled scipy-1.5.4
ERROR: pip's dependency resolver does not currently take into account all the pa
ckages that are installed. This behaviour is the source of the following depende
ncy conflicts.
parl 1.3.2 requires click, which is not installed.
parl 1.3.2 requires flask-cors, which is not installed.
parl 1.3.2 requires psutil>=5.6.2, which is not installed.
parl 1.3.2 requires pyarrow==0.13.0, which is not installed.
parl 1.3.2 requires pyzmq==18.0.1, which is not installed.
parl 1.3.2 requires tb-nightly==1.15.0a20190801, which is not installed.
parl 1.3.2 requires termcolor>=1.1.0, which is not installed.
Successfully installed scipy-1.2.0
ERROR语句为红色 以上解决方法参考:解决ImportError: cannot import name ‘imread’ from ‘scipy.misc’ 另外一个知识点:可以在终端直接输入:
python -c "import scipy; print(scipy.__version__)"
进行查看某包的版本号,而不用一行一行输入:先输入python,再换行输入import scipy,再换行输入print(scipy.version),这种方法太麻烦
在运行程序,还是报错:
Traceback (most recent call last):
File "create_input_files.py", line 1, in <module>
from utils import create_input_files
File "E:\show attend and tell\a-PyTorch-Tutorial-to-Image-Captioning-master\ut
ils.py", line 6, in <module>
from scipy.misc import imread, imresize
ImportError: cannot import name 'imread'
重启了一下终端仍不能导入imread,说明降低scipy版本此方法走不通 再次看另一位博主使用另一种方法:安装imageio 将原先的程序
from scipy.misc import imread, imresize
改为
from imageio import imread
from scipy.misc import imresize
首先安装imageio
pip install imageio
安装结果为:
Installing collected packages: pillow, imageio
ERROR: pip's dependency resolver does not currently take into account all the pa
ckages that are installed. This behaviour is the source of the following depende
ncy conflicts.
matplotlib 3.3.2 requires cycler>=0.10, which is not installed.
matplotlib 3.3.2 requires kiwisolver>=1.0.1, which is not installed.
matplotlib 3.3.2 requires pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3, which is not
installed.
matplotlib 3.3.2 requires python-dateutil>=2.1, which is not installed.
Successfully installed imageio-2.9.0 pillow-8.3.1
以上解决方法参考:解决ImportError: cannot import name ‘imread’ from ‘scipy.misc’ 再次运行程序,报其他错:
(pytorch04) E:\show attend and tell\a-PyTorch-Tutorial-to-Image-Captioning-maste
r>python create_input_files.py
Traceback (most recent call last):
File "create_input_files.py", line 1, in <module>
from utils import create_input_files
File "E:\show attend and tell\a-PyTorch-Tutorial-to-Image-Captioning-master\ut
ils.py", line 9, in <module>
from tqdm import tqdm
ModuleNotFoundError: No module named 'tqdm'
说明使用imageio的方法正确,接下来解决tqdm安装问题 使用
conda install tqdm
使用pip install tqdm也可以,安装完毕后结果为:
done
以上解决方案参考:【解决错误】ModuleNotFoundError: No module named ‘tqdm‘ 再次运行程序出错:
Traceback (most recent call last):
File "create_input_files.py", line 11, in <module>
max_len=50)
File "E:\show attend and tell\a-PyTorch-Tutorial-to-Image-Captioning-master\ut
ils.py", line 31, in create_input_files
with open(karpathy_json_path, 'r') as j:
FileNotFoundError: [Errno 2] No such file or directory: '../caption data/dataset
_coco.json'
说明走到这里的程序已经没有问题,文件路径有错,修改文件路径 我想在pycharm中运行一下程序,所以在pycharm中先要切换一下环境,步骤如下 然后一路点击确定(2个),知道切换成功。 在pycharm中运行程序create_input_files.py,报之前的错误:
Traceback (most recent call last):
File "E:/show attend and tell/a-PyTorch-Tutorial-to-Image-Captioning-master/create_input_files.py", line 11, in <module>
max_len=50)
File "E:\show attend and tell\a-PyTorch-Tutorial-to-Image-Captioning-master\utils.py", line 31, in create_input_files
with open(karpathy_json_path, 'r') as j:
FileNotFoundError: [Errno 2] No such file or directory: '../caption data/dataset_coco.json'
很好!,说明pycharm切换环境成功,接下来修改文件路径 修改后,运行报错:
Traceback (most recent call last):
File "E:/show attend and tell/a-PyTorch-Tutorial-to-Image-Captioning-master/create_input_files.py", line 11, in <module>
max_len=50)
File "E:\show attend and tell\a-PyTorch-Tutorial-to-Image-Captioning-master\utils.py", line 84, in create_input_files
with open(os.path.join(output_folder, 'WORDMAP_' + base_filename + '.json'), 'w') as j:
FileNotFoundError: [Errno 2] No such file or directory: '/media/ssd/caption data/WORDMAP_coco_5_cap_per_img_5_min_word_freq.json'
提示没有文件,那就下载文件,找到网址:
https://drive.google.com/drive/folders/189VY65I_n4RTpQnmLGj7IzVnOF6dmePC
注册登录Google账号,下载更加方便参考我自己注册Google 账号中出现的问题,参考:此电话号码无法用于进行验证。 可以下载文件:WORDMAP_coco_5_cap_per_img_5_min_word_freq.json 另一个文件应该是生成的,所以不用去下载 运行程序,发现这句程序报错:
images = h.create_dataset('images', (len(impaths), 3, 256, 256), dtype='uint8')
报错为:
Traceback (most recent call last):
File "E:/show attend and tell/a-PyTorch-Tutorial-to-Image-Captioning-master/create_input_files.py", line 11, in <module>
max_len=50)
File "E:\show attend and tell\a-PyTorch-Tutorial-to-Image-Captioning-master\utils.py", line 108, in create_input_files
images = h.create_dataset('images', (len(impaths), 3, 256, 256), dtype='uint8')
File "D:\python3\envs\pytorch04\lib\site-packages\h5py\_hl\group.py", line 148, in create_dataset
dsid = dataset.make_new_dset(group, shape, dtype, data, name, **kwds)
File "D:\python3\envs\pytorch04\lib\site-packages\h5py\_hl\dataset.py", line 137, in make_new_dset
dset_id = h5d.create(parent.id, name, tid, sid, dcpl=dcpl)
File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "h5py\h5d.pyx", line 87, in h5py.h5d.create
ValueError: Unable to create dataset (name already exists)
我感觉是
images = h.create_dataset('images', (len(impaths), 3, 256, 256), dtype='uint8')
中的images的名字有重复的了,所以先暂时改名为
images = h.create_dataset('imagesss', (len(impaths), 3, 256, 256), dtype='uint8')
再次运行程序,结果报错:
Traceback (most recent call last):
File "E:/show attend and tell/a-PyTorch-Tutorial-to-Image-Captioning-master/create_input_files.py", line 11, in <module>
max_len=50)
File "E:\show attend and tell\a-PyTorch-Tutorial-to-Image-Captioning-master\utils.py", line 127, in create_input_files
img = imread(impaths[i])
File "D:\python3\envs\pytorch04\lib\site-packages\imageio\core\functions.py", line 265, in imread
reader = read(uri, format, "i", **kwargs)
File "D:\python3\envs\pytorch04\lib\site-packages\imageio\core\functions.py", line 172, in get_reader
request = Request(uri, "r" + mode, **kwargs)
File "D:\python3\envs\pytorch04\lib\site-packages\imageio\core\request.py", line 124, in __init__
self._parse_uri(uri)
File "D:\python3\envs\pytorch04\lib\site-packages\imageio\core\request.py", line 260, in _parse_uri
raise FileNotFoundError("No such file: '%s'" % fn)
FileNotFoundError: No such file: 'E:\media\ssd\caption data\val2014\COCO_val2014_000000522418.jpg'
发现路径'E:\media\ssd\caption data\val2014\COCO_val2014_000000522418.jpg' 没有见到过,
以上方法宣布失败。。。问题出在这句话上images = h.create_dataset('images', (len(impaths), 3, 256, 256), dtype='uint8') ,总是报以下错误,且在网上找不到原因
Traceback (most recent call last):
File "E:/show attend and tell/a-PyTorch-Tutorial-to-Image-Captioning-master/create_input_files.py", line 11, in <module>
max_len=50)
File "E:\show attend and tell\a-PyTorch-Tutorial-to-Image-Captioning-master\utils.py", line 109, in create_input_files
images = h.create_dataset('images', (len(impaths), 3, 256, 256), dtype='uint8')
File "D:\python3\envs\pytorch04\lib\site-packages\h5py\_hl\group.py", line 148, in create_dataset
dsid = dataset.make_new_dset(group, shape, dtype, data, name, **kwds)
File "D:\python3\envs\pytorch04\lib\site-packages\h5py\_hl\dataset.py", line 137, in make_new_dset
dset_id = h5d.create(parent.id, name, tid, sid, dcpl=dcpl)
File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "h5py\h5d.pyx", line 87, in h5py.h5d.create
ValueError: Unable to create dataset (name already exists)
========================================================================
==============================================================================
==============================================================================
==============================================================================
重新创建环境 pytorch:1.5.0
conda create -n pytorch150 python=3.6
在以下网站
https://download.pytorch.org/whl/torch_stable.html
中下载文件
torch-1.5.0+cpu-cp36-cp36m-win_amd64.whl
然后将其放入环境D:\python3\envs\pytorch150\Scripts中,注意是Scripts下 在终端激活环境pytorch150,使用下面命令安装pytorch
pip install torch-1.5.0+cpu-cp36-cp36m-win_amd64.whl
安装其他包:
conda install scipy==1.2.1
conda install nltk
conda install h5py
conda install tqdm
pip 安装也可以,我使用的是pip安装以上包
运行程序报错:
Traceback (most recent call last):
File "create_input_files.py", line 1, in <module>
from utils import create_input_files
File "E:\show attend and tell\a-PyTorch-Tutorial-to-Image-Captioning-master\ut
ils.py", line 6, in <module>
from scipy.misc import imread, imresize
ImportError: cannot import name 'imread'
说明还是没有之前的包,继续安装imageio 将原先的程序
from scipy.misc import imread, imresize
改为
from imageio import imread
from scipy.misc import imresize
运行程序,报错:
Traceback (most recent call last):
File "E:/Show/a-PyTorch-Tutorial-to-Image-Captioning-master/create_input_files.py", line 11, in <module>
max_len=50)
File "E:\Show\a-PyTorch-Tutorial-to-Image-Captioning-master\utils.py", line 31, in create_input_files
with open(karpathy_json_path, 'r') as j:
FileNotFoundError: [Errno 2] No such file or directory: '../caption data/dataset_coco.json'
错误出现在以下程序的karpathy_json_path='../caption data/dataset_coco.json'
from utils import create_input_files
if __name__ == '__main__':
create_input_files(dataset='coco',
karpathy_json_path='../caption data/dataset_coco.json',
image_folder='/media/ssd/caption data/',
captions_per_image=5,
min_word_freq=5,
output_folder='/media/ssd/caption data/',
max_len=50)
在create_input_files.py 中调用了utils.py 中的函数create_input_files
with open(karpathy_json_path, 'r') as j:
data = json.load(j)
这一句中没有找到文件地址,查看文件放置的正确性 修改好文件摆放位置之后,运行程序,正常啦!!! 如下图 再查看文件里面有什么变化没 喔呦!生成了下面的9个文件,和这位大神的实现一样 终于走了一步了,开心的呀~(2021/9/5晚)
开搞!(2021/9/6中午) 看了参考的文章下一步怎么做 该运行train.py了,运行报错:
D:\python3\envs\pytorch150\python.exe E:/Show/a-PyTorch-Tutorial-to-Image-Captioning-master/train.py
Traceback (most recent call last):
File "E:/Show/a-PyTorch-Tutorial-to-Image-Captioning-master/train.py", line 5, in <module>
import torchvision.transforms as transforms
ModuleNotFoundError: No module named 'torchvision'
没有torchvision那就安装,回想起之前博主提起过安装这俩 我是只安装了pytorch1.50+python3.6,当时将pytorch1.50的安装包放在了Script文件下,然后在终端安装的,这次就先试试直接安装吧,
(pytorch150) D:\python3\envs\pytorch150\Lib\site-packages>conda install torchvis
ion==0.6.0
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible so
lve.
PackagesNotFoundError: The following packages are not available from current cha
nnels:
- torchvision==0.6.0
Current channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/noarch
To search for alternate channels that may provide the conda package you're
looking for, navigate to
https://anaconda.org
and use the search bar at the top of the page.
用命令行安装失败了,哈哈哈哈哈,失败原因不管了,那就不用这种方法了 在下面
https://download.pytorch.org/whl/torch_stable.html
下载了名为torchvision-0.6.0+cpu-cp36-cp36m-win_amd64.whl 的文件放在了pytorch150的环境下,具体文件地址是D:\python3\envs\pytorch150\Lib\site-packages ,使用pip install torchvision-0.6.0+cpu-cp36-cp36m-win_amd64.whl 安装好界面是下面的 又可以安装train.py文件啦!!! 运行试试!报错:
D:\python3\envs\pytorch150\python.exe E:/Show/a-PyTorch-Tutorial-to-Image-Captioning-master/train.py
Traceback (most recent call last):
File "E:/Show/a-PyTorch-Tutorial-to-Image-Captioning-master/train.py", line 331, in <module>
main()
File "E:/Show/a-PyTorch-Tutorial-to-Image-Captioning-master/train.py", line 50, in main
with open(word_map_file, 'r') as j:
FileNotFoundError: [Errno 2] No such file or directory: '/media/ssd/caption data\\WORDMAP_coco_5_cap_per_img_5_min_word_freq.json'
Process finished with exit code 1
干!!!!!!! 分析原因:是train.py中的
data_name = 'coco_5_cap_per_img_5_min_word_freq'
设置的不对,因为我使用的是Flickr8k,原代码中使用的是COCO 所以改一下
data_name = 'flickr8k_5_cap_per_img_5_min_word_freq'
在E:\media\ssd\caption data\Flickr8k 中找到WORDMAP_flickr8k_5_cap_per_img_5_min_word_freq.json 文件,以这个名修改上面的data_name ,又因为在train.py的main()函数是用下面的方式处理的,所以省去WORDMAP_ 和.json
word_map_file = os.path.join(data_folder, 'WORDMAP_' + data_name + '.json')
with open(word_map_file, 'r') as j:
word_map = json.load(j)
修改好,在尝试运行,报错:
D:\python3\envs\pytorch150\python.exe E:/Show/a-PyTorch-Tutorial-to-Image-Captioning-master/train.py
Traceback (most recent call last):
File "E:/Show/a-PyTorch-Tutorial-to-Image-Captioning-master/train.py", line 332, in <module>
main()
File "E:/Show/a-PyTorch-Tutorial-to-Image-Captioning-master/train.py", line 51, in main
with open(word_map_file, 'r') as j:
FileNotFoundError: [Errno 2] No such file or directory: '/media/ssd/caption data\\WORDMAP_flickr8k_5_cap_per_img_5_min_word_freq.json'
Process finished with exit code 1
原来是路径也需要修改
data_folder = '/media/ssd/caption data'
改为:
data_folder = '/media/ssd/caption data/Flicker8k/'
运行train.py报以下错:
D:\python3\envs\pytorch150\python.exe E:/Show/a-PyTorch-Tutorial-to-Image-Captioning-master/train.py
Downloading: "https://download.pytorch.org/models/resnet101-5d3b4d8f.pth" to C:\Users\admin/.cache\torch\checkpoints\resnet101-5d3b4d8f.pth
100%|██████████| 170M/170M [01:05<00:00, 2.74MB/s]
Traceback (most recent call last):
File "E:/Show/a-PyTorch-Tutorial-to-Image-Captioning-master/train.py", line 333, in <module>
main()
File "E:/Show/a-PyTorch-Tutorial-to-Image-Captioning-master/train.py", line 118, in main
epoch=epoch)
File "E:/Show/a-PyTorch-Tutorial-to-Image-Captioning-master/train.py", line 164, in train
for i, (imgs, caps, caplens) in enumerate(train_loader):
File "D:\python3\envs\pytorch150\lib\site-packages\torch\utils\data\dataloader.py", line 279, in __iter__
return _MultiProcessingDataLoaderIter(self)
File "D:\python3\envs\pytorch150\lib\site-packages\torch\utils\data\dataloader.py", line 719, in __init__
w.start()
File "D:\python3\envs\pytorch150\lib\multiprocessing\process.py", line 105, in start
self._popen = self._Popen(self)
File "D:\python3\envs\pytorch150\lib\multiprocessing\context.py", line 223, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "D:\python3\envs\pytorch150\lib\multiprocessing\context.py", line 322, in _Popen
return Popen(process_obj)
File "D:\python3\envs\pytorch150\lib\multiprocessing\popen_spawn_win32.py", line 65, in __init__
reduction.dump(process_obj, to_child)
File "D:\python3\envs\pytorch150\lib\multiprocessing\reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)
File "D:\python3\envs\pytorch150\lib\site-packages\h5py\_hl\base.py", line 372, in __getnewargs__
raise TypeError("h5py objects cannot be pickled")
TypeError: h5py objects cannot be pickled
Process finished with exit code 1
分析错误:说明已经下载了resnet模型:resnet101-5d3b4d8f.pth 参考这篇博客,修改如下: 将原代码中的
train_loader = torch.utils.data.DataLoader(
CaptionDataset(data_folder, data_name, 'TRAIN', transform=transforms.Compose([normalize])),
batch_size=batch_size, shuffle=True, num_workers=workers, pin_memory=True)
val_loader = torch.utils.data.DataLoader(
CaptionDataset(data_folder, data_name, 'VAL', transform=transforms.Compose([normalize])),
batch_size=batch_size, shuffle=True, num_workers=workers, pin_memory=True)
的两个num_workers=workers 删除,运行train.py报错:
D:\python3\envs\pytorch150\python.exe E:/Show/a-PyTorch-Tutorial-to-Image-Captioning-master/train.py
Traceback (most recent call last):
File "E:/Show/a-PyTorch-Tutorial-to-Image-Captioning-master/train.py", line 333, in <module>
main()
File "E:/Show/a-PyTorch-Tutorial-to-Image-Captioning-master/train.py", line 118, in main
epoch=epoch)
File "E:/Show/a-PyTorch-Tutorial-to-Image-Captioning-master/train.py", line 181, in train
scores, _ = pack_padded_sequence(scores, decode_lengths, batch_first=True)
ValueError: too many values to unpack (expected 2)
Process finished with exit code 1
上网搜搜报的错是个啥意思嘿
哈哈哈,找到解决方法了,献上链接 修改程序中
scores, _ = pack_padded_sequence(scores, decode_lengths, batch_first=True)
为
scores = pack_padded_sequence(scores, decode_lengths, batch_first=True)[0]
print(scores)
顺便查看一下结果,再运行程序还是出原来的错,只是位置不同了 运行结果:
D:\python3\envs\pytorch150\python.exe E:/Show/a-PyTorch-Tutorial-to-Image-Captioning-master/train.py
我已经运行到这里了
tensor([[-0.0136, 0.0150, 0.0528, ..., 0.2292, -0.2899, 0.3463],
[-0.5298, 0.1216, 0.1333, ..., 0.3054, 0.0307, -0.0306],
[-0.1771, 0.1554, 0.1336, ..., 0.1443, -0.0566, -0.2475],
...,
[ 0.1615, -0.0726, -0.0425, ..., -0.2490, -0.2140, -0.0373],
[-0.1486, -0.3121, -0.3258, ..., -0.3477, -0.5346, 0.3969],
[-0.0918, -0.1189, 0.1954, ..., 0.0450, -0.4835, 0.3521]],
grad_fn=<PackPaddedSequenceBackward>)
Traceback (most recent call last):
File "E:/Show/a-PyTorch-Tutorial-to-Image-Captioning-master/train.py", line 335, in <module>
main()
File "E:/Show/a-PyTorch-Tutorial-to-Image-Captioning-master/train.py", line 118, in main
epoch=epoch)
File "E:/Show/a-PyTorch-Tutorial-to-Image-Captioning-master/train.py", line 184, in train
targets, _ = pack_padded_sequence(targets, decode_lengths, batch_first=True)
ValueError: too many values to unpack (expected 2)
Process finished with exit code 1
修改targets这一行代码为:
targets = pack_padded_sequence(targets, decode_lengths, batch_first=True)[0]
再次运行train.py,出现以下结果:
D:\python3\envs\pytorch150\python.exe E:/Show/a-PyTorch-Tutorial-to-Image-Captioning-master/train.py
我已经运行到这里了
Epoch: [0][0/938] Batch Time 14.813 (14.813) Data Load Time 0.325 (0.325) Loss 8.7799 (8.7799) Top-5 Accuracy 0.000 (0.000)
Process finished with exit code -1
说明train.py已经可以跑了,但是跑的数据量太大,就暂时停下,将Flickr8k的数据量降低,先跑出个demo出来,保证程序能够走通 我选择了100张图片放在路径E:\media\ssd\caption data\Flickr8k\Flicker8k_Dataset 下,运行代码,报错:
D:\python3\envs\pytorch150\python.exe E:/Show/a-PyTorch-Tutorial-to-Image-Captioning-master/create_input_files.py
Reading TRAIN images and captions, storing to file...
0%| | 0/6000 [00:00<?, ?it/s]
Traceback (most recent call last):
File "E:/Show/a-PyTorch-Tutorial-to-Image-Captioning-master/create_input_files.py", line 27, in <module>
max_len=50)
File "E:\Show\a-PyTorch-Tutorial-to-Image-Captioning-master\utils.py", line 117, in create_input_files
img = imread(impaths[i])
File "D:\python3\envs\pytorch150\lib\site-packages\imageio\core\functions.py", line 265, in imread
reader = read(uri, format, "i", **kwargs)
File "D:\python3\envs\pytorch150\lib\site-packages\imageio\core\functions.py", line 172, in get_reader
request = Request(uri, "r" + mode, **kwargs)
File "D:\python3\envs\pytorch150\lib\site-packages\imageio\core\request.py", line 124, in __init__
self._parse_uri(uri)
File "D:\python3\envs\pytorch150\lib\site-packages\imageio\core\request.py", line 260, in _parse_uri
raise FileNotFoundError("No such file: '%s'" % fn)
FileNotFoundError: No such file: 'E:\media\ssd\caption data\Flickr8k\Flicker8k_Dataset\2513260012_03d33305cf.jpg'
Process finished with exit code 1
报错原因是在一个已经将Flickr8k的所有文本数据已经集成为一个json文件:dataset_flickr8k.json 中未找到对应的图片,所以程序会出现找不到文件得错误 而读取该文件的程序为:
with open(karpathy_json_path, 'r') as j:
data = json.load(j)
print(data)
这个文件的路径为karpathy_json_path='../caption data/dataset_flickr8k.json' 所以要保证程序能够运行,只能减小批的大小,将之前删掉的文件重新复制回去,再次运行create_input_files 生成相应文件 把下面的参数维度都改的小一点: 由原来的
emb_dim = 512
attention_dim = 512
decoder_dim = 512
改为
emb_dim = 16
attention_dim = 16
decoder_dim = 16
将
epochs = 120
改为
epochs = 1
跑以下看看~ 没跑完,电脑声音太大,手动暂停了 结果: 总结一下使用的包的版本
(pytorch150) D:\python3\envs\pytorch150\Lib\site-packages>pip list
Package Version
------------------ -------------------
attrs 21.2.0
cached-property 1.5.2
certifi 2021.5.30
cffi 1.14.6
ChatterBot 1.1.0
click 8.0.1
cloudpickle 1.2.1
colorama 0.4.4
cryptography 3.4.8
Flask 1.1.2
future 0.18.2
h5py 3.1.0
imageio 2.9.0
importlib-metadata 4.8.1
Jinja2 2.11.2
joblib 1.0.1
mathparse 0.1.2
matplotlib 3.3.2
mkl-fft 1.3.0
mkl-random 1.1.1
mkl-service 2.3.0
nltk 3.6.2
numpy 1.19.5
pandas 1.1.5
parl 1.3.2
Pillow 8.3.2
Pint 0.17
pip 21.2.2
pyasn1 0.4.8
pyasn1-modules 0.2.8
pycparser 2.20
regex 2021.8.28
scipy 1.2.1
service-identity 21.1.0
setuptools 52.0.0.post20210125
six 1.16.0
tensorboardX 1.8
torch 1.5.0+cpu
torchvision 0.6.0+cpu
tqdm 4.62.2
typing-extensions 3.10.0.2
wheel 0.37.0
wincertstore 0.2
zipp 3.5.0
|