Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.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 关键错误:';标签';在数据培训期间制作模型_Python_Tensorflow_Image Processing_Keras_Computer Vision - Fatal编程技术网

Python 关键错误:';标签';在数据培训期间制作模型

Python 关键错误:';标签';在数据培训期间制作模型,python,tensorflow,image-processing,keras,computer-vision,Python,Tensorflow,Image Processing,Keras,Computer Vision,嗨,我正在使用虚拟环境,为我的项目制作列车模型,并使用keras 2.3.1和tensorflow 2.2.0。我所有的代码都在工作,但我在最后一行运行,出现异常,所以这一行在这里 from Lib.data_loader import DataLoader from Lib.resnet_model import Resnet3DBuilder from Lib.HistoryGraph import HistoryGraph import Lib.image as img from Lib.

嗨,我正在使用虚拟环境,为我的项目制作列车模型,并使用keras 2.3.1和tensorflow 2.2.0。我所有的代码都在工作,但我在最后一行运行,出现异常,所以这一行在这里

from Lib.data_loader import DataLoader
from Lib.resnet_model import Resnet3DBuilder
from Lib.HistoryGraph import HistoryGraph
import Lib.image as img
from Lib.utils import mkdirs
import os
from math import ceil
from keras.optimizers import SGD
from keras.callbacks import ModelCheckpoint
target_size = (64,96)
nb_frames = 16  # here this will get number of pictres from datasets folder
skip = 1 # using resnet we skip different layers
nb_classes = 27
batch_size = 64 
input_shape = (nb_frames,) + target_size + (3,)
workers = 8 
use_multiprocessing = False 
max_queue_size = 20 
data_root = r"D:\FYP\DataSet"
csv_labels = r"D:\FYP\DataSet\jester-v1-labels.csv"
csv_train = r"D:\FYP\DataSet\jester-v1-train.csv"
csv_val = r"D:\FYP\DataSet\jester-v1-validation.csv"
csv_test = r"D:\FYP\DataSet\jester-v1-test.csv  "
data_vid = r"D:\FYP\DataSet\videos"
model_name = 'resent_3d_model'
data_model = r"D:\FYP\DataSet\Model"

path_model = os.path.join(data_root, data_model, model_name)
path_vid = os.path.join(data_root, data_vid)
path_labels = os.path.join(data_root, csv_labels)
path_train = os.path.join(data_root, csv_train)
path_val = os.path.join(data_root, csv_val)
path_test = os.path.join(data_root, csv_test)

data = DataLoader(path_vid, path_labels, path_train, path_val)
mkdirs(path_model, 0o755)
mkdirs(os.path.join(path_model, "graphs"), 0o755)

gen = img.ImageDataGenerator()
gen_train = gen.flow_video_from_dataframe(data.train_df, path_vid, path_classes=path_labels, x_col='video_id', y_col="labels", target_size=target_size, batch_size=batch_size, nb_frames=nb_frames, skip=skip, has_ext=True)
gen_val = gen.flow_video_from_dataframe(data.val_df, path_vid, path_classes=path_labels, x_col='video_id', y_col="labels", target_size=target_size, batch_size=batch_size, nb_frames=nb_frames, skip=skip, has_ext=True)

resnet_model = Resnet3DBuilder.build_resnet_101(input_shape, nb_classes, drop_rate = 0.5)

optimizer = SGD(lr=0.01, momentum=0.9, decay=0.0001, nesterov=False)

resnet_model.compile(optimizer = optimizer, loss= "categorical_crossentropy" , metrics=["accuracy"])

model_file = os.path.join(path_model, 'resnetmodel.hdf5')

model_checkpointer = ModelCheckpoint(model_file, monitor='val_acc',verbose=1, save_best_only=True, mode='max')

history_graph = HistoryGraph(model_path_name = os.path.join(path_model, "graphs"))

nb_sample_train = data.train_df["video_id"].size
nb_sample_val = data.val_df["video_id"].size

resnet_model.fit_generator( 
                        generator = gen_train,
                        steps_per_epoch = ceil(nb_sample_train/batch_size),
                        epochs=100,
                        validation_data=gen_val,
                        validation_steps=30,
                        shuffle=True,
                        verbose=1,
                        workers=workers,
                        max_queue_size = max_queue_size,
                        use_multiprocessing = use_multiprocessing,
                        callbacks = [model_checkpointer, history_graph])
当我运行最后一行时,错误在下面

  Epoch 1/100
C:\Users\Virus\anaconda3\envs\HandGestureRecognitionSystem\lib\site-packages\keras\utils\data_utils.py:613: UserWarning: The input 80 could not be retrieved. It could be because a worker has died.
  warnings.warn(
---------------------------------------------------------------------------
TimeoutError                              Traceback (most recent call last)
~\anaconda3\envs\HandGestureRecognitionSystem\lib\site-packages\keras\utils\data_utils.py in get(self)
    609                     future = self.queue.get(block=True)
--> 610                     inputs = future.get(timeout=30)
    611                 except mp.TimeoutError:

~\anaconda3\envs\HandGestureRecognitionSystem\lib\multiprocessing\pool.py in get(self, timeout)
    766         if not self.ready():
--> 767             raise TimeoutError
    768         if self._success:

TimeoutError: 

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
~\anaconda3\envs\HandGestureRecognitionSystem\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
   3079             try:
-> 3080                 return self._engine.get_loc(casted_key)
   3081             except KeyError as err:

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'labels'

The above exception was the direct cause of the following exception:

KeyError                                  Traceback (most recent call last)
<ipython-input-15-6810853f4b54> in <module>
----> 1 resnet_model.fit_generator( 
      2                         generator = gen_train,
      3                         steps_per_epoch = ceil(nb_sample_train/batch_size),
      4                         epochs=100,
      5                         validation_data=gen_val,

~\anaconda3\envs\HandGestureRecognitionSystem\lib\site-packages\keras\legacy\interfaces.py in wrapper(*args, **kwargs)
     89                 warnings.warn('Update your `' + object_name + '` call to the ' +
     90                               'Keras 2 API: ' + signature, stacklevel=2)
---> 91             return func(*args, **kwargs)
     92         wrapper._original_function = func
     93         return wrapper

~\anaconda3\envs\HandGestureRecognitionSystem\lib\site-packages\keras\engine\training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
   1716         ```
   1717         """
-> 1718         return training_generator.fit_generator(
   1719             self, generator,
   1720             steps_per_epoch=steps_per_epoch,

~\anaconda3\envs\HandGestureRecognitionSystem\lib\site-packages\keras\engine\training_generator.py in fit_generator(model, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
    183             batch_index = 0
    184             while steps_done < steps_per_epoch:
--> 185                 generator_output = next(output_generator)
    186 
    187                 if not hasattr(generator_output, '__len__'):

~\anaconda3\envs\HandGestureRecognitionSystem\lib\site-packages\keras\utils\data_utils.py in get(self)
    623         except Exception:
    624             self.stop()
--> 625             six.reraise(*sys.exc_info())
    626 
    627 

~\anaconda3\envs\HandGestureRecognitionSystem\lib\site-packages\six.py in reraise(tp, value, tb)
    701             if value.__traceback__ is not tb:
    702                 raise value.with_traceback(tb)
--> 703             raise value
    704         finally:
    705             value = None

~\anaconda3\envs\HandGestureRecognitionSystem\lib\site-packages\keras\utils\data_utils.py in get(self)
    615                         ' It could be because a worker has died.'.format(idx),
    616                         UserWarning)
--> 617                     inputs = self.sequence[idx]
    618                 finally:
    619                     self.queue.task_done()

D:\HandGesturesProject\Lib\image.py in __getitem__(self, idx)
   1534         index_array = self.index_array[self.batch_size * idx:
   1535                                        self.batch_size * (idx + 1)]
-> 1536         return self._get_batches_of_transformed_samples(index_array)
   1537 
   1538     def common_init(self, image_data_generator,

D:\HandGesturesProject\Lib\image.py in _get_batches_of_transformed_samples(self, index_array)
   2243                 dtype=self.dtype)
   2244 
-> 2245             for i, label in enumerate(self.df.iloc[index_array][self.y_col].values):
   2246                 batch_y[i, self.classes_indices[label]] = 1
   2247 

~\anaconda3\envs\HandGestureRecognitionSystem\lib\site-packages\pandas\core\frame.py in __getitem__(self, key)
   3022             if self.columns.nlevels > 1:
   3023                 return self._getitem_multilevel(key)
-> 3024             indexer = self.columns.get_loc(key)
   3025             if is_integer(indexer):
   3026                 indexer = [indexer]

您的错误在
Lib.img
中,它可能是一个自定义模块。没有这个模块,我们无法调试它。所以我能做什么,先生,我如何上传文件或发送给你。我只是在代码中使用这个生成器类及其函数:gen=img.ImageDataGenerator()gen\u train=gen.flow\u video\u from\u dataframe(data.train\u df,path\u vid,path\u classes=path\u labels,x\u col='video\u id',y\u col=“labels”,target\u size=target\u size,batch\u size=batch\u size,nb\u frames=nb\u frames,skip=skip,has\u ext=True)gen\val=gen.flow\u video\u from\u dataframes(data.val\u df,path\u vid,path\u classes=path\u labels,x\u col='video\u id',y\u col=“labels”,target\u size=target\u size=target\u size,batch\u size=batch\u size=batch\u size,nb\u frames=nb\u frames=nb,skip,has\u ext
    Anyone help me how to deal with it thankyou.