Я пытаюсь тренировать модель Pre dNet. Я сталкиваюсь со следующей ошибкой всякий раз, когда я запускаю kitti_train.py. Я запускаю его на Windows системе с tenorsflow версии 2.0.0 и keras версии 2.3.1, и у меня есть графический процессор.
Модель: "model_3" Слой (тип) Тип выходной формы Параметр #
input_3 (InputLayer) (Нет, 10, 128, 160, 3) 0
pred_net_3 (Pre dNet) (Нет, 10, 4) 6915948
time_distributed_3 (TimeDist (None, 10, 1) 5
flatten_3 (Flatten) (None, 10) 0 density_6 (Плотный) (None, 1) 11
Всего параметров: 6 915 964 Обучаемых параметров: 6 915 948 Не обучаемые параметры: 16
Нет Epoch 1/150 Traceback (последний вызов был последним):
Файл ".. \ pre dnet -master \ kitti_train.py", строка 80 , в истории = model.fit_generator (train_generator, samples_per_epoch / batch_size, nb_epoch, verbose = 1, обратные вызовы = обратные вызовы, validation_data = val_generator, validation_steps = N_seq_val / batch_size)
файл \ lib \ \ \ " -packages \ keras \ legacy \ interfaces.py ", строка 91, в оболочке возвращает удовольствие c (* args, ** kwargs)
Файл" .. \ Anaconda3 \ lib \ si te-packages \ keras \ engine \ training.py ", строка 1732, в fit_generator initial_epoch = initial_epoch)
Файл" .. \ Anaconda3 \ lib \ site-packages \ keras \ engine \ training_generator.py ", строка 220, в fit_generator reset_metrics = False)
Файл ".. \ Anaconda3 \ lib \ site-packages \ keras \ engine \ training.py", строка 1514, в файле train_on_batch output = self.train_function (ins)
Файл ".. \ Anaconda3 \ lib \ site-packages \ tenorflow_core \ python \ keras \ backend.py", строка 3740, в выходных данных вызова = self._graph_fn (* convert_inputs)
Файл ".. \ Anaconda3 \ lib \ site-packages \ tenorflow_core \ python \ eager \ function.py", строка 1081, при вызове return self._call_impl (args, kwargs)
Файл ".. \ Anaconda3 \ lib \ site-packages \ tenorflow_core \ python \ eager \ function.py ", строка 1121, в _call_impl возвращает self._call_flat (args, self.captured_inputs, cancellation_manager)
Файл" .. \ Anaconda3 \ lib \ site-packages \ tenorflow_core \ python \ eager \ function.py ", строка 1224, в _call_flat ctx, args, cancellati on_manager = cancellation_manager)
Файл ".. \ Anaconda3 \ lib \ site-packages \ tenorflow_core \ python \ eager \ function.py", строка 511, в вызове ctx = ctx)
Файл ".. \ Anaconda3 \ lib \ site-packages \ tenorflow_core \ python \ eager \ execute.py", строка 67, в quick_execute six.raise_from (core._status_to_exception (e.code, message), нет)
Файл "", строка 3, в lift_from
FailedPreconditionError: Ошибка при чтении переменной ресурса _AnonymousVar459 из Container: localhost. Это может означать, что переменная была неинициализирована. Не найдено: Ресурс localhost / _AnonymousVar459 / class tenorflow :: Var не существует. [[узел pred_net_3 / MatMul_3 / ReadVariableOp (определено в .. \ Anaconda3 \ lib \ site-packages \ tenorflow_core \ python \ framework \ ops.py: 1751)]] [Op: __ inference_keras_scratch_graph_36245]
стек вызовов функций : keras_scratch_graph `
import os
import numpy as np
np.random.seed(123)
from six.moves import cPickle
from tensorflow.compat.v1.keras import backend as K
from keras.models import Model
from keras.layers import Input, Dense, Flatten
from keras.layers import LSTM
from keras.layers import TimeDistributed
from keras.callbacks import LearningRateScheduler, ModelCheckpoint
from keras.optimizers import Adam
from prednet import PredNet
from data_utils import SequenceGenerator
from kitti_settings import *
from tensorflow import keras
import tensorflow as tf
from tensorflow.python.keras.backend import set_session
from tensorflow.python.keras.models import load_model
save_model = True # if weights will be saved
weights_file = os.path.join(WEIGHTS_DIR, 'prednet_kitti_weights.hdf5') # where weights will be saved
json_file = os.path.join(WEIGHTS_DIR, 'prednet_kitti_model.json')
# Data files
train_file = os.path.join(DATA_DIR, 'X_train.hkl')
train_sources = os.path.join(DATA_DIR, 'sources_train.hkl')
val_file = os.path.join(DATA_DIR, 'X_val.hkl')
val_sources = os.path.join(DATA_DIR, 'sources_val.hkl')
# Training parameters
nb_epoch = 150
batch_size = 4
samples_per_epoch = 500
N_seq_val = 100 # number of sequences to use for validation
# Model parameters
n_channels, im_height, im_width = (3, 128, 160)
input_shape = (n_channels, im_height, im_width) if K.image_data_format() == 'channels_first' else (im_height, im_width, n_channels)
stack_sizes = (n_channels, 48, 96, 192)
R_stack_sizes = stack_sizes
A_filt_sizes = (3, 3, 3)
Ahat_filt_sizes = (3, 3, 3, 3)
R_filt_sizes = (3, 3, 3, 3)
layer_loss_weights = np.array([1., 0., 0., 0.]) # weighting for each layer in final loss; "L_0" model: [1, 0, 0, 0], "L_all": [1, 0.1, 0.1, 0.1]
layer_loss_weights = np.expand_dims(layer_loss_weights, 1)
nt = 10 # number of timesteps used for sequences in training
time_loss_weights = 1./ (nt - 1) * np.ones((nt,1)) # equally weight all timesteps except the first
time_loss_weights[0] = 0
prednet = PredNet(stack_sizes, R_stack_sizes,
A_filt_sizes, Ahat_filt_sizes, R_filt_sizes,
output_mode='error', return_sequences=True)
inputs = Input(shape=(nt,) + input_shape)
errors = prednet(inputs) # errors will be (batch_size, nt, nb_layers)
errors_by_time = TimeDistributed(Dense(1, trainable=False), weights=[layer_loss_weights, np.zeros(1)], trainable=False)(errors) # calculate weighted error by layer
errors_by_time = Flatten()(errors_by_time) # will be (batch_size, nt)
final_errors = Dense(1, weights=[time_loss_weights, np.zeros(1)], trainable=False)(errors_by_time) # weight errors by time
model = Model(inputs=inputs, outputs=final_errors)
model.compile(loss='mean_absolute_error', optimizer='adam')
train_generator = SequenceGenerator(train_file, train_sources, nt, batch_size=batch_size, shuffle=True)
val_generator = SequenceGenerator(val_file, val_sources, nt, batch_size=batch_size, N_seq=N_seq_val)
lr_schedule = lambda epoch: 0.001 if epoch < 75 else 0.0001 # start with lr of 0.001 and then drop to 0.0001 after 75 epochs
callbacks = [LearningRateScheduler(lr_schedule)]
if save_model:
if not os.path.exists(WEIGHTS_DIR): os.mkdir(WEIGHTS_DIR)
callbacks.append(ModelCheckpoint(filepath=weights_file, monitor='val_loss', save_best_only=True))
print(model.summary())
history = model.fit_generator(train_generator,samples_per_epoch / batch_size, nb_epoch, verbose=1, callbacks=callbacks,validation_data=val_generator,validation_steps=N_seq_val / batch_size)
if save_model:
json_string = model.to_json()
with open(json_file, "w") as f:
f.write(json_string)`