Giter Club home page Giter Club logo

rivagan's Introduction

RivaGAN PyTorch (Unofficial)

😯 Before We Start...

This repository is created to assist people encountering difficulties running the offical repository from DAI-Lab, as the official one has not received updates for the past several years. Additionally, I have optimized the official version to enhance execution speed while maintaining overall performance integrity. Lastly, I have conducted testing on Windows 11 using the latest Python 3.11 and PyTorch 2.0.1

😀 Prerequisites

  1. Install PyTorch, Numpy, OpenCV, Pandas, ArgParse
  2. Install GitBash from https://git-scm.com/
  3. Install wget from https://gnuwin32.sourceforge.net/packages/wget.htm
  4. Install Torch DCT using pip install torch_dct

🤪 Let's Get Started!

  1. Clone this repository

  2. Open GitBash Terminal and Download Hollywood2 Training Dataset
    Acquiring the dataset may require several hours, depending upon the speed of your internet connection

    cd data
    bash download.sh
    
  3. Train RivaGAN Model
    The hyperparameter settings align with the official specifications and are currently configured to their default values

    python train.py 
    python train.py --epochs 200 --lr 0.001 --data_dim 64 
    

    Default Hyperparameters Details:

    • --epochs: 300
    • --train_batch: 12
    • --lr: 0.0005
    • --num_workers: 16
    • --data_dim: 32
    • --use_critic: True
    • --use_adversary: True
    • --use_noise: True
    • --use_bit_inverse: True
  4. Inference RivaGAN Model
    After completing the model training, our objective is to encode a data watermark onto a video and subsequently extract it from the encoded footage. After the inference process, it will generate output_log.txt file, providing a detailed record of the extracted data from each frame in the video and a watermarked video that contains the data

    python inference.py --model_weight your_weight_path/model.pt
    python inference.py --model_weight your_weight_path/model.pt --random_data No --your_data "1100 1001 0011 0000 1111 0101 1100 0011" --fps 30
    

    Default Hyperparameters Details:

    • --data_dim: 32
      • The data dimensions must correspond with the dimensions used during the model training
    • --model_weight: None
      • Must be added
    • --random_data: Yes
    • --your_data: None
      • Set --random_data to No to use your own data
    • --video_location: ./data/hollywood2/val/actioncliptest00002.avi
    • --fps: 25
      • Watermaked video output FPS

Changelog

2024-05-23

  • make_pair function has been reverted to its original code due to instability issues during training

2024-04-18

  • Incorporated pre-trained RivaGAN model, which was trained using 32-bit data dimensions

2023-01-23

  • Enhanced code optimization for encoding and decoding processes (3.5 ~ 4x speed increase)

rivagan's People

Contributors

peachypie98 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rivagan's Issues

loss一直不收敛

运行了模型 下载了数据 跑了三百论 loss一直是1.3 精度也不高 只有0.6 左右 这种怎么调节去解决 改变了学习率那个loss也降不下

Saving the model with state_dict

Hi, thanks for the amazing work.

I was wondering if you could help me in modifying the code so that the model is saved by using its state_dict, instead of saving the whole model, as PyTorch documentation suggests (https://pytorch.org/tutorials/beginner/saving_loading_models.html).

Since the RivaGAN class does not extend directly the nn.Module, I tought to simply modify it from class RivaGAN(object) to class RivaGAN(nn.Module)

and then change from

torch.save(self, os.path.join(log_dir, "model.pt"))

to

torch.save(self.state_dict(), os.path.join(log_dir, "model.pt"))

but maybe I'm missing something and I can't figure out if it's enough for the model to work properly or if this modification could alter the model behavior when loaded (since the RivaGAN class is composed by multiple sub-modules).

Do you have any suggestion?
Thanks

Checkpoints

Thank you for sharing the code! Do you have trained checkpoints or is there a way to use their official checkpoint, which ends with .onnx? Thanks!

Robustness to horizontal flipping

Hi, thank you for this amazing work of refactoring the original source code of RivaGAN.

I was wondering if you have any suggestion on how to give more robustness to the model against horizontal flipping attacks.

I trained the model, but after some experiments I noticed that flipping the video leads to very poor accuracy in watermark extraction.

I tried to implement a simple noise layer like this:

class HorizontalFlipping(nn.Module):
    """
    Simulates a transformation where the input is mirrored horizontally.

    Input: (N, 3, L, H, W)
    Output: (N, 3, L, H, W)
    """

    def __init__(self):
        super(HorizontalFlipping, self).__init__()

    def forward(self, frames):
        #return frames.flip(dims=(-1,))
        return frames.flip([4]) #flips along the width dimension

and then I added it inside the training and validation code, similarly to the others noise layers already implemented (Crop, Compression, Scale).

The problem is, when I run a new training with such modifications, the various accuracies have a worsening (included the validation crop accuracy, scale accuracy, ...).

Do you have any suggestions?
Thanks a lot

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.