diff --git a/data/README.md b/data/README.md
index 890c364..360c808 100644
--- a/data/README.md
+++ b/data/README.md
@@ -1,14 +1,21 @@
+
+
# π Voice2Face-Data
+
+
+
+
## Project Structure
+
```
data
β£ audio
β β£ audio_check_dB.py
-β β£ audio_crop.py
+β β£ audio_dB_crop.py
β β audio_wav_cropping.py
β£ crawling
β β£ crawling_detect.py
@@ -29,54 +36,103 @@ data
β£ video
β β£ video_clipimage.py
β β video_download.py
-β README.md
+β£ README.md
β requirements.txt
```
+## Usage
+
+
+
+#### audio
+ - `audio_check_dB.py`: νΉμ dB κ°μ νμΈνμ¬ μ¬λμ μμ± μ¬λΆλ₯Ό νλ³νλ μ€ν¬λ¦½νΈμ
λλ€.
+ - `audio_dB_crop.py`: μ€λμ€ νμΌμμ μΈκ°μ λͺ©μ리 μΈκ·Έλ¨ΌνΈλ₯Ό μΆμΆνκ³ κ°μ§λ μμ± μΈκ·Έλ¨ΌνΈλ₯Ό ν¬ν¨νλ μλ‘μ΄ μ€λμ€ νμΌμ 10μ΄λ‘ μλ₯΄λ μ€ν¬λ¦½νΈμ
λλ€.
+ - `audio_wav_cropping.py`: JSON POINTμ λ§μΆ° μ€λμ€λ₯Ό μλ₯΄λ μ€ν¬λ¦½νΈμ
λλ€.
+
+#### crawling
+
+ - `crawling_detect.py`: λΉλμ€ ν΄λ¦½μμ μΌκ΅΄κ³Ό μ€λμ€λ₯Ό κ°μ§νκ³ μΈλΆννλ μ€ν¬λ¦½νΈμ
λλ€.
+ - `crawling_rename_video.py`: 'download' ν΄λμμ λΉλμ€ μ΄λ¦κ³Ό CSVμ μΈλ±μ€λ₯Ό λ§μΆλ μ€ν¬λ¦½νΈμ
λλ€.
+ - `crawling_select_csv.py`: μ£Όμ΄μ§ CSV νμΌμμ YouTube IDλ₯Ό μ°Ύμ ν΄λΉνλ νμΌ μ΄λ¦μμ μ 보λ₯Ό μΆμΆνκ³ , μ΄ μ 보λ₯Ό μλ‘μ΄ CSV νμΌμ μ μ₯νλ κ°λ¨ν λ°μ΄ν° μ²λ¦¬ μμ
μ μννλ μ€ν¬λ¦½νΈμ
λλ€.
+ - `crawling_urlsave.py`: Seleniumμ μ¬μ©νμ¬ YouTube ν¬λ‘€λ§μ μννμ¬ μ½ 162κ°μ λΉλμ€μ λν μ΄λ¦, μ λͺ© λ° URL μ 보λ₯Ό Youtube_search_df.csvμ μ μ₯νλ μ€ν¬λ¦½νΈμ
λλ€.
+ - `crawling_videosave.py`: '`crawling_urlsave.py`'λ₯Ό ν΅ν΄ μ»μ URLμμ λΉλμ€λ₯Ό λ€μ΄λ‘λνλ μ€ν¬λ¦½νΈμ
λλ€. λΉλμ€λ 'download' ν΄λμ μ μ₯λ©λλ€.
+
+#### image
+
+ - `image_clipseg2.py`: CLIPSeg λͺ¨λΈμ μ¬μ©νμ¬ ν
μ€νΈ ν둬ννΈλ₯Ό κΈ°λ°μΌλ‘ μ΄λ―Έμ§ μΈλΆνλ₯Ό μννλ μ€ν¬λ¦½νΈμ
λλ€. μ΄λ―Έμ§λ₯Ό λΆλ¬μ ν
μ€νΈ ν둬ννΈλ‘ μ²λ¦¬νκ³ , μλ³λ κ°μ²΄λ₯Ό κΈ°λ°μΌλ‘ μΈλΆνλ μ΄λ―Έμ§λ₯Ό μμ±ν©λλ€.
+ - `image_face_frame.py`: λΉλμ€μμ μ¬λμ μΌκ΅΄μ΄ μ λ©΄μ΄κ³ , λμ λ¨κ³ μμ λ μΊ‘μ³νκ³ λ°°κ²½μ μ κ±°νλ μ€ν¬λ¦½νΈμ
λλ€.
+
+#### relabel
+
+ - `relabel_detect_getframe.py`: μ£Όμ΄μ§ λΉλμ€μμ μΌκ΅΄μ κ°μ§νκ³ , κ°μ§λ μΌκ΅΄μ λν΄ μ±λ³κ³Ό μ°λ Ήμ μΆμ νμ¬ νλ©΄μ νμνκ³ , μΌμ ν κ°κ²©μΌλ‘ νλ μμ μΊ‘μ²νμ¬ μ΄λ―Έμ§ νμΌλ‘ μ μ₯νλ κΈ°λ₯μ μνν©λλ€.
+ - `relabel_select_csv.py`: λ°μ΄ν° κ²½λ‘μμ YouTube IDλ₯Ό μΆμΆνκ³ , νμΌ μ΄λ¦μμ νμν μ 보λ₯Ό μΆμΆνμ¬ μλ‘μ΄ CSV νμΌμ μ μ₯νλ μ€ν¬λ¦½νΈμ
λλ€.
+ - `relabel_Vox_age.py`: μ΄λ―Έμ§ ν΄λμμ μ΄λ―Έμ§λ€μ μ½μ΄μ κ° μ΄λ―Έμ§μ λμ΄λ₯Ό μμΈ‘νκ³ , κ°μ₯ νν λμ΄ κ·Έλ£Ήμ μΈμ μΆλ ₯νκ³ , κ·Έ κ²°κ³Όλ₯Ό CSV νμΌμ μ μ₯νλ μμ
μ μνν©λλ€.
+
+#### video
+
+ - `video_clipimage.py`: μ£Όμ΄μ§ μ΄λ―Έμ§μμ μΌκ΅΄μ κ°μ§νκ³ , κ°μ§λ μΌκ΅΄ μμμ μ¬κ°νμΌλ‘ νμν ν ν΄λΉ μΌκ΅΄μ 256x256 ν¬κΈ°λ‘ μ‘°μ νμ¬ μ μ₯νλ μμ
μ μνν©λλ€.
+ - `video_download.py`: μ£Όμ κΈ°λ₯μ μ£Όμ΄μ§ YouTube λΉλμ€ λ§ν¬μμ λΉλμ€λ₯Ό λ€μ΄λ‘λνκ³ , λ€μ΄λ‘λν λΉλμ€λ₯Ό mp4 λλ mp3 νμμΌλ‘ λ³ννλ μ€ν¬λ¦½νΈμ
λλ€.
+
+#### total
+- `total_audio_video_image.py`: μ€λμ€, λΉλμ€ λ° μ΄λ―Έμ§μ κ΄λ ¨λ μμ
μ μ΄ μννλ μ€ν¬λ¦½νΈμ
λλ€.
+- `total_origin_remove.py`: λ°μ΄ν° κ²½λ‘μμ μλ³Έ νμΌμ μ κ±°νλ μ€ν¬λ¦½νΈμ
λλ€.
+
+
+
## Getting Started
+
### Setting up Vitual Enviornment
+
1. Initialize and update the server
- ```
- su -
- source .bashrc
- ```
-2. Create and Activate a virtual environment in the project directory
+```
- ```
- conda create -n env python=3.8
- conda activate env
- ```
+su -
-4. To deactivate and exit the virtual environment, simply run:
+source .bashrc
- ```
- deactivate
- ```
+```
-### Install Requirements
+
+
+2. Create and Activate a virtual environment in the project directory
+
+
-To Insall the necessary packages liksted in `requirements.txt`, run the following command while your virtual environment is activated:
```
-pip install -r requirements.txt
+
+conda create -n env python=3.8
+
+conda activate env
+
```
-## Usage
+
-#### Training
+4. To deactivate and exit the virtual environment, simply run:
-To train the model with your custom dataset, set the appropriate directories for the training images and model saving, then run the training script.
+
```
-python train.py --data_dir /path/to/images --model_dir /path/to/model
+
+deactivate
+
```
-#### Inference
+
+
+### Install Requirements
+
+
-For generating predictions with a trained model, provide directories for evaluation data, the trained model, and output, then run the inference script.
+To Install the necessary packages liksted in `requirements.txt`, run the following command while your virtual environment is activated:
```
-python inference.py --data_dir /path/to/images --model_dir /path/to/model --output_dir /path/to/model
+
+pip install -r requirements.txt
+
```
+
+
\ No newline at end of file
diff --git a/data/audio/audio_crop.py b/data/audio/audio_dB_crop.py
similarity index 100%
rename from data/audio/audio_crop.py
rename to data/audio/audio_dB_crop.py
diff --git a/data/crawling/crawling_select_csv.py b/data/crawling/crawling_select_csv.py
index 1bab567..64097a7 100644
--- a/data/crawling/crawling_select_csv.py
+++ b/data/crawling/crawling_select_csv.py
@@ -3,19 +3,34 @@
from argparse import ArgumentParser
def parse_args():
+ """
+ Command-line arguments parser.
+
+ Returns:
+ argparse.Namespace: Parsed arguments.
+ """
parser = ArgumentParser()
- # Conventional args
- parser.add_argument('--csv_file', type=str, default='output_test.csv')
- parser.add_argument('--data_path', type=str, default='origin/video')
- parser.add_argument('--save_csv', type=str, default='new_output.csv')
+ parser.add_argument('--csv_file', type=str, default='output_test.csv',
+ help="Path to the CSV file containing data.")
+ parser.add_argument('--data_path', type=str, default='origin/video',
+ help="Path to the directory containing files and folders.")
+ parser.add_argument('--save_csv', type=str, default='new_output.csv',
+ help="Path to save the new CSV file.")
args = parser.parse_args()
-
return args
-
def list_files_and_folders(data_path):
+ """
+ List files and folders in the given directory path.
+
+ Args:
+ data_path (str): Path to the directory.
+
+ Returns:
+ list or None: List of files and folders if directory exists, otherwise None.
+ """
if os.path.isdir(data_path):
items = os.listdir(data_path)
return items
@@ -23,20 +38,37 @@ def list_files_and_folders(data_path):
return None
def main(csv_file, data_path, save_csv):
+ """
+ Main function to process data.
+ Args:
+ csv_file (str): Path to the CSV file.
+ data_path (str): Path to the directory containing files and folders.
+ save_csv (str): Path to save the new CSV file.
+ """
+ # Read CSV file
csv_data = pd.read_csv(csv_file, header=None)
+
+ # Get list of files and folders in the data path
youtube_ids = list_files_and_folders(data_path)
+ # Process each YouTube ID
for youtube_id in youtube_ids:
+ # Filter rows corresponding to the YouTube ID
filtered_df = csv_data[csv_data[0].astype(str).str.contains(youtube_id)]
first_row = filtered_df.iloc[0:1]
+
+ # Extract information from file name
file_name = list_files_and_folders(os.path.join(data_path, youtube_id))[0]
file_name_list = file_name.split("_")
- first_row[4] = file_name_list[0]
- first_row[5] = file_name_list[1]
+
+ # Add extracted information as new columns
+ first_row[4] = file_name_list[0]
+ first_row[5] = file_name_list[1]
+
+ # Save to new CSV file
first_row.to_csv(save_csv, mode="a", index=False, header=False)
-
if __name__ == '__main__':
args = parse_args()
- main(**args.__dict__)
\ No newline at end of file
+ main(**args.__dict__)
diff --git a/data/requirements.txt b/data/requirements.txt
new file mode 100644
index 0000000..6a236ce
--- /dev/null
+++ b/data/requirements.txt
@@ -0,0 +1,18 @@
+opencv-python
+rembg
+librosa
+numpy
+matplotlib
+soundfile
+pydub
+pandas
+moviepy
+face_recognition
+selenium
+requests
+beautifulsoup4
+pytube
+transformers
+Pillow
+torch
+facenet-pytorch
diff --git a/data/video/video_clipimage.py b/data/video/video_clipimage.py
index eb4e39c..e5c1bfb 100644
--- a/data/video/video_clipimage.py
+++ b/data/video/video_clipimage.py
@@ -1,31 +1,41 @@
import cv2
-face_cascade = cv2.CascadeClassifier('code/file/haarcascade_frontalface_default.xml')
-
-# μ΄λ―Έμ§ μ½κΈ°
-img = cv2.imread('code/file/image.png')
-gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
-
-# μΌκ΅΄ κ°μ§
-faces = face_cascade.detectMultiScale(gray, 1.3, 5)
-
-# κ° μΌκ΅΄μ λν΄ λ°λ³΅
-for (x, y, w, h) in faces:
- # μΌκ΅΄ μμμ μ¬κ°ν 그리기
- cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2)
-
- # μΌκ΅΄ μμμ 256x256 ν¬κΈ°λ‘ μ‘°μ
- face_crop = cv2.resize(img[y:y+h, x:x+w], (256, 256))
+def detect_and_save_faces(image_path, output_path):
+ """Detects faces in the input image and saves them as 256x256 pixel images.
- # μΌκ΅΄ μ΄λ―Έμ§ μ μ₯
- cv2.imwrite('code/file/face_detected_256x256.png', face_crop)
-
-# μ΄λ―Έμ§ 보μ¬μ£ΌκΈ°
-cv2.imshow('Image view', img)
-
-# 'q' ν€λ₯Ό λλ₯Ό λκΉμ§ λκΈ°
-while cv2.waitKey(0) & 0xFF != ord('q'):
- pass
-
-cv2.destroyAllWindows()
-
+ Args:
+ image_path (str): Path to the input image file.
+ output_path (str): Path to save the detected face images.
+ """
+ # Load the pre-trained face cascade classifier
+ face_cascade = cv2.CascadeClassifier('code/file/haarcascade_frontalface_default.xml')
+
+ # Read the input image
+ img = cv2.imread(image_path)
+ gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
+
+ # Detect faces
+ faces = face_cascade.detectMultiScale(gray, 1.3, 5)
+
+ # Iterate over each detected face
+ for (x, y, w, h) in faces:
+ # Draw rectangle around the face
+ cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2)
+
+ # Resize the face region to 256x256 pixels
+ face_crop = cv2.resize(img[y:y+h, x:x+w], (256, 256))
+
+ # Save the face image
+ cv2.imwrite(output_path, face_crop)
+
+ # Display the image
+ cv2.imshow('Image view', img)
+
+ # Wait for 'q' key to be pressed
+ while cv2.waitKey(0) & 0xFF != ord('q'):
+ pass
+
+ cv2.destroyAllWindows()
+
+# Example usage
+detect_and_save_faces('code/file/image.png', 'code/file/face_detected_256x256.png')
diff --git a/data/video/video_download.py b/data/video/video_download.py
index faeeb96..5b156a0 100644
--- a/data/video/video_download.py
+++ b/data/video/video_download.py
@@ -7,7 +7,14 @@ class Download:
'''
νμΌμ λ³ννκΈ° μν΄μ ffmpegλ νλ‘κ·Έλ¨μ λ³λλ‘ μ€μΉν΄ μ»΄ν¨ν° νκ²½λ³μ μ€μ μ λ§μ³μΌ ν¨.
'''
+
def __init__(self, link):
+ '''
+ Download ν΄λμ€μ μμ±μμ
λλ€.
+
+ Args:
+ link (str): μ νλΈ μμμ λ§ν¬.
+ '''
# link μΈμλ GUIμμ μ
λ ₯λ κ°μ λ°μ λ μ¬μ©
# μ»΄ν¨ν° μ΄μ©μλͺ
μ λ°μμ λ€μ΄λ‘λ ν΄λλ₯Ό κΈ°λ³Έ ν΄λλ‘ μ§μ
self.parent_dir = f"/Users/{getuser()}/Documents/voice2face-data/code/file"
@@ -15,11 +22,23 @@ def __init__(self, link):
def getVideoName(self):
'''(GUI λ²μ ) λΉλμ€ μ΄λ¦μ λ΄λ³΄λ΄λ ν¨μ'''
+ '''
+ μ νλΈ λΉλμ€μ μ λͺ©μ λ°ννλ ν¨μμ
λλ€.
+
+ Returns:
+ str: λΉλμ€μ μ λͺ©.
+ '''
name = self.yt.title
return name
def downloadMp3(self):
'''mp3 νμΌλ‘ λ€μ΄λ‘λνλ ν¨μ'''
+ '''
+ mp3 νμμΌλ‘ λΉλμ€λ₯Ό λ€μ΄λ‘λνλ ν¨μμ
λλ€.
+
+ Returns:
+ str: λ€μ΄λ‘λν mp3 νμΌμ μ΄λ¦.
+ '''
# mp4 ννμ§λ§ μμ μμ΄ μλ¦¬λ§ μλ νμΌ λ€μ΄λ‘λ
stream = self.yt.streams.filter(only_audio=True).first()
stream.download(self.parent_dir)
@@ -37,6 +56,12 @@ def downloadMp3(self):
def downloadMp4(self):
'''mp4 νμΌλ‘ λ€μ΄λ‘λνλ ν¨μ'''
+ '''
+ mp4 νμμΌλ‘ λΉλμ€λ₯Ό λ€μ΄λ‘λνλ ν¨μμ
λλ€.
+
+ Returns:
+ str: λ€μ΄λ‘λν mp4 νμΌμ μ΄λ¦.
+ '''
audio = self.downloadMp3() # mp3 νμΌ λ€μ΄λ‘λ
video = self.yt.streams.filter(adaptive=True, file_extension='mp4').first() # λΉλμ€ κ°μ²΄ κ°μ Έμ€κΈ°
print(video)