Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 利用Cnn&;Lstm?_Python_Python 3.x_Lstm - Fatal编程技术网

Python 利用Cnn&;Lstm?

Python 利用Cnn&;Lstm?,python,python-3.x,lstm,Python,Python 3.x,Lstm,1.这一部分我得到的输出是创建了一个“descriptions.txt”文件 # Set these path according to project folder in you system dataset_text = 'C:\\Users\Srikanth Bhattu\Project\Flickr8k_text\Flickr8k.token.txt' dataset_images = 'C:\\Users\Srikanth Bhattu\Project\Flickr8k_Dataset

1.这一部分我得到的输出是创建了一个“descriptions.txt”文件

# Set these path according to project folder in you system
dataset_text = 'C:\\Users\Srikanth Bhattu\Project\Flickr8k_text\Flickr8k.token.txt'
dataset_images = 'C:\\Users\Srikanth Bhattu\Project\Flickr8k_Dataset\Flicker8k_Dataset'
#we prepare our text data
filename = dataset_text + "/" + 'C:\\Users\Srikanth Bhattu\Project\Flickr8k_text\Flickr8k.token.txt'
#loading the file that contains all data
#mapping them into descriptions dictionary img to 5 captions
descriptions = all_img_captions()
print("Length of descriptions =" ,len(descriptions))
#cleaning the descriptions
clean_descriptions = cleaning_text(descriptions)
#building vocabulary 
vocabulary = text_vocabulary()
print("Length of vocabulary = ", len(vocabulary))
#saving each description to file 
save_descriptions()
2.帮助我加载图像数据集并生成如下给定输出

def extract_features(directory):
        model = Xception( include_top=False, pooling='avg' )
        features = {}
        for img in tqdm(os.listdir(directory)):
            filename = directory + "/" + img
            image = Image.open(filename)
            image = image.resize((299,299))
            image = np.expand_dims(image, axis=0)
            #image = preprocess_input(image)
            image = image/127.5
            image = image - 1.0
            feature = model.predict(image)
            features[img] = feature
        return features
#2048 feature vector
features = extract_features(dataset_images)
dump(features, open("features.p","wb"))
错误:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-246-e6797fb99786> in <module>
      1 #2048 feature vector
----> 2 features = extract_features(dataset_images)
      3 dump(features, open('C:\\Users\Srikanth Bhattu\Project\features.p','wb'))

<ipython-input-242-ab5029ed6c28> in extract_features(directory)
      1 def extract_features(directory):
----> 2         model = Xception( include_top=False, pooling='avg' )
      3         features = {}
      4         for img in tqdm(os.listdir(directory)):
      5             filename = directory + "/" + img

NameError: name 'Xception' is not defined.
---------------------------------------------------------------------------
NameError回溯(最近一次呼叫上次)
在里面
1#2048特征向量
---->2个特征=提取特征(数据集图像)
3转储(功能,打开('C:\\Users\Srikanth Bhattu\Project\features.p','wb'))
在提取功能(目录)中
1 def提取功能(目录):
---->2模型=异常(包括\u top=False,pooling='avg')
3个功能={}
4对于tqdm(os.listdir(目录))中的img:
5文件名=目录+“/”+img
NameError:未定义名称“Exception”。
我需要这个输出图像:

我正在使用CNN&LSTM使用图像字幕生成器。我有所有的源代码和数据集,但我不能在代码中包含我的数据集和路径。 如果有人有兴趣帮助我完成我的项目,请发表评论,我将向他们支付一些费用。
谢谢你

您在共享的代码段中没有名为“Exception”的模型的定义。因此,除非定义模型或导入模型,否则它将无法工作。我猜您正在学习本教程

仔细阅读,你会发现他们在文章的开头已经导入了模型,这样做应该没问题。按顺序阅读文章,你将不会遇到问题

import string
import numpy as np
from PIL import Image
import os
from pickle import dump, load
import numpy as np
from keras.applications.xception import Xception, preprocess_input
from keras.preprocessing.image import load_img, img_to_array
from keras.preprocessing.text import Tokenizer
from keras.preprocessing.sequence import pad_sequences
from keras.utils import to_categorical
from keras.layers.merge import add
from keras.models import Model, load_model
from keras.layers import Input, Dense, LSTM, Embedding, Dropout
# small library for seeing the progress of loops.
from tqdm import tqdm_notebook as tqdm
tqdm().pandas()

必须在运行代码段之前执行这些命令。它将导入异常模型和您正在使用的其他库。

您能用更多细节更新您的问题吗?问题过于宽泛。帖子已更新。。!请按照您上面提到的相同教程,完成本手册-Rohan BojjaYes-Rohan bojja iam。我已经得到了3个部分的输出,但是我在这个提取特征部分中有所收获。谢谢你的回答,我会照你在keras.applications.xception import xception中提到的那样做,预处理输入这一行应该在你运行代码段之前执行。-Rohan Bojja导入“from keras.applications.xception import xception”后,我的代码运行成功。非常感谢你的帮助。。。!你好,你能帮我用CNN&LSTM@Rohan生成图片标题吗Bojja@SrikanthBhattu你能告诉我更多关于你面临的问题吗?