質問編集履歴
3
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -38,7 +38,21 @@
|
|
38
38
|
|
39
39
|
from tensorflow.keras.models import load_model
|
40
40
|
|
41
|
-
|
41
|
+
#tokenizerをloadする
|
42
|
+
|
43
|
+
tokenizer = load(open('tokenizer1.pkl', 'rb'))
|
44
|
+
|
45
|
+
#trainigしたときのpre-defineでmax sequence lengthの値
|
46
|
+
|
47
|
+
max_length = 43
|
48
|
+
|
49
|
+
#modelのload
|
50
|
+
|
51
|
+
model = load_model('model-ep004-loss2.778-val_loss3.210.h5')
|
52
|
+
|
53
|
+
#text_readingに使われる画像のpath
|
54
|
+
|
55
|
+
text_reading_image_path ='image2.png'
|
42
56
|
|
43
57
|
class Image_captioning: #説明文を生成するクラス
|
44
58
|
|
@@ -96,6 +110,88 @@
|
|
96
110
|
|
97
111
|
return feature
|
98
112
|
|
113
|
+
# map an integer to a word
|
114
|
+
|
115
|
+
def word_for_id(self,integer, tokenizer):
|
116
|
+
|
117
|
+
for word, index in tokenizer.word_index.items():
|
118
|
+
|
119
|
+
if index == integer:
|
120
|
+
|
121
|
+
return word
|
122
|
+
|
123
|
+
return None
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
# generate a description for an image
|
128
|
+
|
129
|
+
def generate_desc(self,model, tokenizer, photo, max_length):
|
130
|
+
|
131
|
+
# seed the generation process
|
132
|
+
|
133
|
+
in_text = 'startseq'
|
134
|
+
|
135
|
+
# iterate over the whole length of the sequence
|
136
|
+
|
137
|
+
for i in range(max_length):
|
138
|
+
|
139
|
+
# integer encode input sequence
|
140
|
+
|
141
|
+
sequence = tokenizer.texts_to_sequences([in_text])[0]
|
142
|
+
|
143
|
+
# pad input
|
144
|
+
|
145
|
+
sequence = pad_sequences([sequence], maxlen=max_length)
|
146
|
+
|
147
|
+
# predict next word
|
148
|
+
|
149
|
+
yhat = model.predict([photo,sequence], verbose=0)
|
150
|
+
|
151
|
+
# convert probability to integer
|
152
|
+
|
153
|
+
yhat = argmax(yhat)
|
154
|
+
|
155
|
+
# map integer to word
|
156
|
+
|
157
|
+
word = self.word_for_id(yhat, tokenizer)
|
158
|
+
|
159
|
+
# stop if we cannot map the word
|
160
|
+
|
161
|
+
if word is None:
|
162
|
+
|
163
|
+
break
|
164
|
+
|
165
|
+
# append as input for generating the next word
|
166
|
+
|
167
|
+
in_text += ' ' + word
|
168
|
+
|
169
|
+
# stop if we predict the end of the sequence
|
170
|
+
|
171
|
+
if word == 'endseq':
|
172
|
+
|
173
|
+
break
|
174
|
+
|
175
|
+
return in_text
|
176
|
+
|
177
|
+
def text_reading(self):
|
178
|
+
|
179
|
+
photo = self.extract_features(text_reading_image_path)
|
180
|
+
|
181
|
+
d = self.generate_desc(model, tokenizer, photo, max_length)
|
182
|
+
|
183
|
+
description = d.replace('startseq',' ',1).replace('endseq',' ',1)
|
184
|
+
|
185
|
+
print(description)
|
186
|
+
|
187
|
+
sound = gTTS(text=description,lang='ja',slow=False)
|
188
|
+
|
189
|
+
sound.save('/home/limlab/program/navigation/potential/voice/navigation.mp3')
|
190
|
+
|
191
|
+
playsound('/home/limlab/program/voice/1.wav')
|
192
|
+
|
193
|
+
playsound("/home/limlab/program/navigation/potential/voice/navigation.mp3")
|
194
|
+
|
99
195
|
#ここからはエラーメッセージとなります
|
100
196
|
|
101
197
|
a
|
2
モジュールのインポートを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -23,6 +23,22 @@
|
|
23
23
|
### コードとエラーメッセージになります
|
24
24
|
|
25
25
|
```
|
26
|
+
|
27
|
+
from tensorflow.keras.preprocessing.sequence import pad_sequences
|
28
|
+
|
29
|
+
from tensorflow.keras.applications.vgg16 import VGG16
|
30
|
+
|
31
|
+
from tensorflow.keras.preprocessing.image import load_img
|
32
|
+
|
33
|
+
from tensorflow.keras.preprocessing.image import img_to_array
|
34
|
+
|
35
|
+
from tensorflow.keras.applications.vgg16 import preprocess_input
|
36
|
+
|
37
|
+
from tensorflow.keras.models import Model
|
38
|
+
|
39
|
+
from tensorflow.keras.models import load_model
|
40
|
+
|
41
|
+
|
26
42
|
|
27
43
|
class Image_captioning: #説明文を生成するクラス
|
28
44
|
|
1
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,51 +20,117 @@
|
|
20
20
|
|
21
21
|
|
22
22
|
|
23
|
-
###
|
23
|
+
### コードとエラーメッセージになります
|
24
|
+
|
25
|
+
```
|
26
|
+
|
27
|
+
class Image_captioning: #説明文を生成するクラス
|
28
|
+
|
29
|
+
# extract features from each photo in the directory
|
30
|
+
|
31
|
+
def extract_features(self,filename):
|
32
|
+
|
33
|
+
print('a')
|
34
|
+
|
35
|
+
# load the model
|
36
|
+
|
37
|
+
model = VGG16()
|
38
|
+
|
39
|
+
print('b')
|
40
|
+
|
41
|
+
# re-structure the model
|
42
|
+
|
43
|
+
model.layers.pop()
|
44
|
+
|
45
|
+
print('c')
|
46
|
+
|
47
|
+
model = Model(inputs=model.inputs, outputs=model.layers[-1].output)
|
48
|
+
|
49
|
+
print('d')
|
50
|
+
|
51
|
+
# load the photo
|
52
|
+
|
53
|
+
image = load_img(filename, target_size=(224, 224))
|
54
|
+
|
55
|
+
print('e')
|
56
|
+
|
57
|
+
# convert the image pixels to a numpy array
|
58
|
+
|
59
|
+
image = img_to_array(image)
|
60
|
+
|
61
|
+
print('f')
|
62
|
+
|
63
|
+
# reshape data for the model
|
64
|
+
|
65
|
+
image = image.reshape((1, image.shape[0], image.shape[1], image.shape[2]))
|
66
|
+
|
67
|
+
print('g')
|
68
|
+
|
69
|
+
# prepare the image for the VGG model
|
70
|
+
|
71
|
+
image = preprocess_input(image)
|
72
|
+
|
73
|
+
print("h")
|
74
|
+
|
75
|
+
# get features
|
76
|
+
|
77
|
+
feature = model.predict(image, verbose=0)
|
78
|
+
|
79
|
+
print('i')
|
80
|
+
|
81
|
+
return feature
|
82
|
+
|
83
|
+
#ここからはエラーメッセージとなります
|
84
|
+
|
85
|
+
a
|
86
|
+
|
87
|
+
2021-11-21 11:58:17.479209: I tensorflow/stream_executor/cuda/cuda_driver.cc:775] failed to allocate 1.00G (1073741824 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY: out of memory
|
88
|
+
|
89
|
+
2021-11-21 11:58:17.479540: I tensorflow/stream_executor/cuda/cuda_driver.cc:775] failed to allocate 921.60M (966367744 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY: out of memory
|
90
|
+
|
91
|
+
2021-11-21 11:58:17.479817: I tensorflow/stream_executor/cuda/cuda_driver.cc:775] failed to allocate 829.44M (869731072 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY: out of memory
|
92
|
+
|
93
|
+
2021-11-21 11:58:17.480066: I tensorflow/stream_executor/cuda/cuda_driver.cc:775] failed to allocate 746.50M (782758144 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY: out of memory
|
94
|
+
|
95
|
+
2021-11-21 11:58:17.480313: I tensorflow/stream_executor/cuda/cuda_driver.cc:775] failed to allocate 671.85M (704482304 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY: out of memory
|
96
|
+
|
97
|
+
2021-11-21 11:58:17.480559: I tensorflow/stream_executor/cuda/cuda_driver.cc:775] failed to allocate 604.66M (634034176 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY: out of memory
|
98
|
+
|
99
|
+
2021-11-21 11:58:18.318427: W tensorflow/core/framework/cpu_allocator_impl.cc:81] Allocation of 411041792 exceeds 10% of free system memory.
|
100
|
+
|
101
|
+
b
|
102
|
+
|
103
|
+
c
|
104
|
+
|
105
|
+
d
|
106
|
+
|
107
|
+
e
|
108
|
+
|
109
|
+
f
|
110
|
+
|
111
|
+
g
|
112
|
+
|
113
|
+
h
|
114
|
+
|
115
|
+
2021-11-21 11:58:18.680658: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcublas.so.10
|
116
|
+
|
117
|
+
2021-11-21 11:58:18.779763: E tensorflow/stream_executor/cuda/cuda_blas.cc:225] failed to create cublas handle: CUBLAS_STATUS_NOT_INITIALIZED
|
118
|
+
|
119
|
+
2021-11-21 11:58:18.781533: E tensorflow/stream_executor/cuda/cuda_blas.cc:225] failed to create cublas handle: CUBLAS_STATUS_NOT_INITIALIZED
|
120
|
+
|
121
|
+
2021-11-21 11:58:18.782176: E tensorflow/stream_executor/cuda/cuda_blas.cc:225] failed to create cublas handle: CUBLAS_STATUS_NOT_INITIALIZED
|
122
|
+
|
123
|
+
2021-11-21 11:58:18.782845: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudnn.so.7
|
124
|
+
|
125
|
+
2021-11-21 11:58:18.785736: E tensorflow/stream_executor/cuda/cuda_dnn.cc:328] Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
|
126
|
+
|
127
|
+
2021-11-21 11:58:18.786488: E tensorflow/stream_executor/cuda/cuda_dnn.cc:328] Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
|
128
|
+
|
129
|
+
2021-11-21 11:58:18.786504: W tensorflow/core/framework/op_kernel.cc:1767] OP_REQUIRES failed at conv_ops_fused_impl.h:642 : Unknown: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above.
|
24
130
|
|
25
131
|
|
26
132
|
|
27
133
|
```
|
28
|
-
|
29
|
-
2021-11-19 19:55:06.734805: I tensorflow/stream_executor/cuda/cuda_driver.cc:775] failed to allocate 1.00G (1073741824 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY: out of memory
|
30
|
-
|
31
|
-
2021-11-19 19:55:06.735052: I tensorflow/stream_executor/cuda/cuda_driver.cc:775] failed to allocate 921.60M (966367744 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY: out of memory
|
32
|
-
|
33
|
-
2021-11-19 19:55:06.735269: I tensorflow/stream_executor/cuda/cuda_driver.cc:775] failed to allocate 829.44M (869731072 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY: out of memory
|
34
|
-
|
35
|
-
2021-11-19 19:55:06.735488: I tensorflow/stream_executor/cuda/cuda_driver.cc:775] failed to allocate 746.50M (782758144 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY: out of memory
|
36
|
-
|
37
|
-
2021-11-19 19:55:06.735701: I tensorflow/stream_executor/cuda/cuda_driver.cc:775] failed to allocate 671.85M (704482304 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY: out of memory
|
38
|
-
|
39
|
-
2021-11-19 19:55:06.735926: I tensorflow/stream_executor/cuda/cuda_driver.cc:775] failed to allocate 604.66M (634034176 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY: out of memory
|
40
|
-
|
41
|
-
2021-11-19 19:55:06.736143: I tensorflow/stream_executor/cuda/cuda_driver.cc:775] failed to allocate 544.20M (570630912 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY: out of memory
|
42
|
-
|
43
|
-
2021-11-19 19:55:07.551528: W tensorflow/core/framework/cpu_allocator_impl.cc:81] Allocation of 411041792 exceeds 10% of free system memory.
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
2021-11-19 19:55:07.882426: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcublas.so.10
|
48
|
-
|
49
|
-
2021-11-19 19:55:07.937269: E tensorflow/stream_executor/cuda/cuda_blas.cc:225] failed to create cublas handle: CUBLAS_STATUS_NOT_INITIALIZED
|
50
|
-
|
51
|
-
2021-11-19 19:55:07.938436: E tensorflow/stream_executor/cuda/cuda_blas.cc:225] failed to create cublas handle: CUBLAS_STATUS_NOT_INITIALIZED
|
52
|
-
|
53
|
-
2021-11-19 19:55:07.939484: E tensorflow/stream_executor/cuda/cuda_blas.cc:225] failed to create cublas handle: CUBLAS_STATUS_NOT_INITIALIZED
|
54
|
-
|
55
|
-
2021-11-19 19:55:07.940272: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudnn.so.7
|
56
|
-
|
57
|
-
2021-11-19 19:55:07.942591: E tensorflow/stream_executor/cuda/cuda_dnn.cc:328] Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
|
58
|
-
|
59
|
-
2021-11-19 19:55:07.943814: E tensorflow/stream_executor/cuda/cuda_dnn.cc:328] Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
|
60
|
-
|
61
|
-
2021-11-19 19:55:07.943831: W tensorflow/core/framework/op_kernel.cc:1767] OP_REQUIRES failed at conv_ops_fused_impl.h:642 : Unknown: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above.
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
```
|
66
|
-
|
67
|
-
|
68
134
|
|
69
135
|
|
70
136
|
|