我正在尝试使用tflearn
训练,保存和加载张量流模型Sub testy2ElectricBoogaloo()
dim i as long, ans as boolean
Dim mystr As String
ans = False
ReDim arr(1 To Worksheets.Count, 1 To 2)
For i = 1 To UBound(arr)
arr(i, 1) = Worksheets(i).Name
'My code makes every password simply the sheet name followed by a smiley face.
'Adjust to fit your actual passwords.
arr(i, 2) = Worksheets(i).Name & " :)"
Next i
Do While ans = False
mystr = InputBox("Please enter password to continue.", "Enter Password")
If mystr = vbNullString Then Exit Sub
For i = 1 To ThisWorkbook.Worksheets.Count
If mystr = arr(i, 2) Then ans = True: Worksheets(arr(i, 1)).Visible = True: Exit For
Next i
Loop
End Sub
这部分有效。接下来,我做
# Building convolutional network
network = input_data(shape=[None, imageSize, imageSize, 1], name='input')
network = conv_2d(network, imageSize, self.windowSize, activation='relu', regularizer="L2")
network = max_pool_2d(network, 2)
network = local_response_normalization(network)
network = conv_2d(network, imageSize * 2, self.windowSize, activation='relu', regularizer="L2")
network = max_pool_2d(network, 2)
network = local_response_normalization(network)
network = fully_connected(network, (dim4 * dim4) * (imageSize * 2), activation='tanh')
network = dropout(network, keep)
network = fully_connected(network, (dim4 * dim4) * (imageSize * 2), activation='tanh')
network = dropout(network, keep)
network = fully_connected(network, n_classes, activation='softmax')
network = regression(network, optimizer='adam', learning_rate=self.learningRate,
loss='categorical_crossentropy', name='target')
model = tflearn.DNN(network, tensorboard_verbose=0, tensorboard_dir='some/dir')
model.fit(
{'input': np.array(myData.train_x).reshape(-1, self.imageSize, self.imageSize, 1)}, {'target': myData.train_y}, n_epoch=self.epochs,
validation_set=(
{'input': np.array(myData.test_x).reshape(-1, self.imageSize, self.imageSize, 1)},
{'target': myData.test_y}),
snapshot_step=100, show_metric=True, run_id='convnet')
model.save("some/path/model")
这在 model_path = "some/path/model.meta"
if os.path.exists(model_path):
model.load(model_path)
else :
return "need to train the model"
prediction = self.model.predict([<some_input>])
print(str(prediction))
return prediction
失败了。我得到以下错误跟踪
model.load(model_path)
是什么意思
DataLossError (see above for traceback): Unable to open table file some/path/model.meta: Data loss: not an sstable (bad magic number): perhaps your file is in a different file format and you need to use a different restore operator?
[[Node: save_5/RestoreV2_4 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_save_5/Const_0_0, save_5/RestoreV2_4/tensor_names, save_5/RestoreV2_4/shape_and_slices)]]
Caused by op 'save_5/RestoreV2_4', defined at:
我可以看到模型确实正确保存并且不是空文件。为什么我不能加载它?
版本信息
Data loss: not an sstable (bad magic number): perhaps your file is in a different file format and you need to use a different restore operator?
答案 0 :(得分:1)
答案:
如评论中所述,保存变量的路径必须包含“.ckpt”文件名。
同样,应通过相同的“.ckpt”文件进行恢复