gpt4 book ai didi

TypeError: expected str, bytes or os.PathLike object, not DataFrame : Videoclassification(TypeError:应为str、bytes或os.PathLike对象,而不是DataFrame:Video分类)

转载 作者:bug小助手 更新时间:2023-10-28 11:48:28 29 4
gpt4 key购买 nike



I'm working on a video classification model and have encountered an error when trying to create a training dataset using the labeled_video_dataset function from PyTorchVideo.

我正在处理视频分类模型,在尝试使用来自PyTorchVideo的Label_VIDEO_DataSet函数创建训练数据集时遇到错误。


Here's an overview of what I've done so far:

以下是我到目前为止所做工作的概述:


I loaded a dataset from Google Drive that contains video files.
I created labels for these videos (0 for "Normal" and 1 for "Shoplifting").
I turned this data into a Pandas DataFrame, where each row contains the video file path and its corresponding label.
I split this DataFrame into a training set (train_df) and a validation set (val_df) using train_test_split.
Now, I want to create a training dataset for my video classification model using the following code:

我从Google Drive加载了一个包含视频文件的数据集。我为这些视频创建了标签(0代表“正常”,1代表“入店行窃”)。我将这些数据转换为Pandas DataFrame,其中每一行都包含视频文件路径及其对应的标签。我使用TRAIN_TEST_SPLIT将这个DataFrame拆分成一个训练集(Train_Df)和一个验证集(Val_Df)。现在,我想使用以下代码为我的视频分类模型创建一个训练数据集:


from torch.utils.data import DataLoader
from pytorchvideo.data import labeled_video_dataset

# Create a training dataset
train_dataset = labeled_video_dataset(
df, # Provide the DataFrame directly
clip_sampler=make_clip_sampler(clipmode, video_duration),
transform=video_transform,
decode_audio=False
)

# Create a DataLoader for the training dataset
train_loader = DataLoader(
train_dataset,
batch_size=batch_size,
num_workers=0,
pin_memory=True
)

However, I'm encountering the following error:

但是,我遇到了以下错误:


TypeError: expected str, bytes, or os.PathLike object, not DataFrame


I have already installed all the necessary libraries and modules, and the DataFrame df appears to be correctly formatted. Can someone please help me identify the issue and provide guidance on how to resolve it?

我已经安装了所有必需的库和模块,并且DataFrame DF似乎格式正确。有没有人能帮我找出这个问题并提供解决方法的指导?


Here is more code for context:

以下是上下文的更多代码:


import os
import pandas as pd

base_path = '/content/drive/MyDrive/Shoplifting Dataset (2022) - CV Laboratory MNNIT Allahabad/Shoplifting Dataset (2022) - CV Laboratory MNNIT Allahabad/Dataset/Dataset/'

normal_path = os.path.join(base_path, 'Normal')
shoplifting_path = os.path.join(base_path, 'Shoplifting')

if os.path.exists(normal_path) and os.path.exists(shoplifting_path):
normal_files = [os.path.join(normal_path, filename) for filename in os.listdir(normal_path) if filename.endswith('.mp4')]
shoplifting_files = [os.path.join(shoplifting_path, filename) for filename in os.listdir(shoplifting_path) if filename.endswith('.mp4')]

# Create label lists
normal_labels = [0] * len(normal_files)
shoplifting_labels = [1] * len(shoplifting_files)

# Combine the lists of paths and labels
all_files = normal_files + shoplifting_files
all_labels = normal_labels + shoplifting_labels

# Create a DataFrame
data = {'Video_Path': all_files, 'Label': all_labels}
df = pd.DataFrame(data)

# Print the first 5 rows
print(df.head())
else:
print(f"One or both of the directories '{normal_path}' and '{shoplifting_path}' do not exist.")



from sklearn.model_selection import train_test_split
train_df, val_df = train_test_split(df, test_size=0.25)

I get the error in this section:

我在这一节中得到了错误:


from torch.utils.data import DataLoader, Dataset,ConcatDataset,default_collate
from torch.utils.data import DistributedSampler
from pytorchvideo.data import labeled_video_dataset

# Create a training dataset
train_dataset = labeled_video_dataset(
df, # Provide the DataFrame directly
clip_sampler=make_clip_sampler(clipmode, video_duration),
transform=video_transform,
decode_audio=False
)

# Create a DataLoader for the training dataset
train_loader = DataLoader(
train_dataset,
batch_size=batch_size,
num_workers=0,
pin_memory=True
)

更多回答

You're making us guess where the error happened. Please provide the full error traceback message.

你在让我们猜测错误发生在哪里。请提供完整的错误回溯消息。

优秀答案推荐
更多回答

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com