Code Monkey home page Code Monkey logo

image_manipulation_detection's Introduction

Image_manipulation_detection

Paper: CVPR2018, Learning Rich Features for Image Manipulation Detection
Code based on Faster-RCNN

This is a rough implementation of the paper. Since I do not have a titan gpu, I made some modifications on the algorithm, but you can easily change them back if you want the exact setting from the paper.

Environment

Python 3.6 TensorFlow 1.8.0

Setup

  • Download vgg16 pre-trained weights from here
    • save to /data/imagenet_weights/vgg16.ckpt
  • Two-stream neural network model: lib/nets/vgg16.py
    • noise stream's weights are randomly initialized
    • for accurate prediction, please pre-train noise stream's vgg weights on ImageNet and overwrite the trainable setting of noise stream after SRM conv layer
  • Bounding boxes are predicted by both streams.
    • In the paper, RGB stream alone predicts bbox more accurately, so you may wanna change that as well (also defined in vgg16.py)
  • Use main_create_training_set.py to create training set from PASCAL VOC dataset.
    • The generated dataset will follow the pascal voc style, which is also required by train.py
  • Tensorboard file will be save at /default
  • Weights will be save to /default/DIY_detaset/default

Note

The code requires a large memory GPU. If you do not have a 6G+ GPU, please reduce the number of noise stream conv layers for training.

Demo results

Dataset size: 10000, epoch: 3

Finally

I will update this repo a few weeks later after I installed the new GPU

image_manipulation_detection's People

Contributors

larryjiang134 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

image_manipulation_detection's Issues

Pre trained model error

The link to the pretrained model has not been given. On running demo_two_stream.py I receive the following error

 Traceback (most recent call last):
  File "demo_two_stream.py", line 124, in <module>
    'our server and place them properly?').format(tfmodel + '.meta'))
OSError: default/DIY_dataset/default/vgg16_faster_rcnn_iter_30000.ckpt.meta not found.

Original Research Paper Changes.

Hello. I just wanted to know what are the changes that we need to make in order to fully implement the research paper, in case I am using a Titan GPU?

train data

In this paper, casia dataset obtains the ground truth mask by tampering with the difference between the image and the original image and performing threshold processing. How is this done? What method is used?

UserWarning: Converting sparse IndexedSlices to a dense Tensor of unknown shape.

Hi @LarryJiang134 ,when I trained the model with train.py,I received this warning:
UserWarning: Converting sparse IndexedSlices to a dense Tensor of unknown shape. This may consume a large amount of memory. "Converting sparse IndexedSlices to a dense Tensor of unknown shape. "

and this mistake:
Allocator (GPU_0_bfc) ran out of memory trying to allocate 3.49GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
However,my GPU has 8G memory and 6.5G of free memory. Is it true that the program requires 8G+ of memory? Is it possible to train on the basis of not modifying the network?

'vgg16' object has no attribute '_anchor_target_layer'

how can i fix follow question??
File "C:\deep learning test\Image_manipulation_detection\lib\nets\vgg16.py", line 272, in build_proposals
rpn_labels = self._anchor_target_layer(rpn_cls_score, "anchor")
AttributeError: 'vgg16' object has no attribute '_anchor_target_layer'

How to test and evaluate the model

Thank you for the code. I have reproduced it now. But I don't know how to evaluate and test the model. I want to use the F1 score to evaluate the model (you can also use the tamper data set you provided to test it). The test data set used is Colombia, but I have encountered difficulties in writing the evaluation code and have been bothering me for many days. If you can provide the code, thank you for your help.

Training pipeline

Hi,
I don't understand the SETUP instructions completely, especially this sentence: for accurate prediction, please pre-train noise stream's vgg weights on ImageNet and overwrite the trainable setting of noise stream after SRM conv layer. Does it mean, that first I train only the noise stream on ImageNet by setting trainable = False for the RGB stream, and after this I train both streams on the PASCAL VOC dataset together? Could someone explain the overall pipeline to me?

bbx_pred的预测流不太对

按照源论文的描述,最终bbox的预测使用的rgb流出来的Rol feature,但看代码中使用的是Bilinear polling出来的结果既做了cls_pred,也做了bbox_pred,见lib/net/vgg16.py

cls_score = slim.fully_connected(fc7_cbp, self._num_classes, weights_initializer=initializer, trainable=is_training, activation_fn=None, scope='cls_score')
cls_prob = self._softmax_layer(cls_score, "cls_prob")
bbox_prediction = slim.fully_connected(fc7_cbp, self._num_classes * 4, weights_initializer=initializer_bbox, trainable=is_training, activation_fn=None, scope='bbox_pred')

是否应该改为:

# bbox的预测使用rgb流来做
pool5_flat = slim.flatten(pool5, scope='rgb_flatten')
# Fully connected layers
fc6 = slim.fully_connected(pool5_flat, 4096, scope='rgb_fc6')
if is_training:
fc6 = slim.dropout(fc6, keep_prob=0.5, is_training=True, scope='rgb_dropout6')

fc7 = slim.fully_connected(fc6, 4096, scope='rgb_fc7')
if is_training:
fc7 = slim.dropout(fc7, keep_prob=0.5, is_training=True, scope='rgb_dropout7')

bbox_prediction = slim.fully_connected(fc7, self._num_classes * 4, weights_initializer=initializer_bbox,
trainable=is_training, activation_fn=None, scope='bbox_pred')

Accuracy is very low

I am not getting true result.Some results are false and on some images it is not showing tampering level.
Thanks in advance

No file named trainval.txt

Hi, I am getting this error:

Traceback (most recent call last):
File "main_create_training_set.py", line 25, in
imdb = get_imdb("voc_2007_trainval")
File "/home/ubuntu/Image_manipulation_detection/lib/datasets/factory.py", line 48, in get_imdb
return __setsname
File "/home/ubuntu/Image_manipulation_detection/lib/datasets/factory.py", line 24, in
__sets[name] = (lambda split=split, year=year: pascal_voc(split, year))
File "/home/ubuntu/Image_manipulation_detection/lib/datasets/pascal_voc.py", line 41, in init
self._image_index = self._load_image_set_index()
File "/home/ubuntu/Image_manipulation_detection/lib/datasets/pascal_voc.py", line 101, in _load_image_set_index
'Path does not exist: {}'.format(image_set_file)
AssertionError: Path does not exist: /home/ubuntu/Image_manipulation_detection/data/VOCDevkit2007/VOC2007/ImageSets/Main/trainval.txt

Pdb errors

please have a look at blew errors when i run "python train.py",thanks very much.
...
speed: 1.673s / iter
iter: 30 / 40000, total loss: 0.681241

rpn_loss_cls: 0.105365
rpn_loss_box: 0.005859
loss_cls: 0.264825
loss_box: 0.305192

speed: 1.405s / iter

/data/sam.yi/Image_manipulation_detection/lib/layer_utils/proposal_target_layer.py(139)_sample_rois()
-> keep_inds = np.append(fg_inds, bg_inds)
(Pdb)
(Pdb)
(Pdb)
(Pdb)
(Pdb)

How to pre-train noise stream's vgg weights on ImageNet?

hello, can you talk about the pre-train noise stream's vgg weights on ImageNet more details?
thanks.
for accurate prediction, please pre-train noise stream's vgg weights on ImageNet and overwrite the trainable setting of noise stream after SRM conv layer

train data

Can you show the specific training data? I downloaded the data, but there is no trainval.txt

a error with use command "python train.py"

hello ,buddy:
I run command "python train.py" at the directory "Image_manipulation_detection-master/train.py",the terminal show the error "File "/tmp/pycharm_project_48/Image_manipulation_detection-master/lib/utils/bbox.py", line 8
cimport cython
^
SyntaxError: invalid syntax
"
I already run "python utils/setup.py install",but i dont know what mean about the line of "cimport cython" in the file of train.py,and why occur the error

per-pixel F1 score

To calculate the per-pixel F1 score, a probability map is needed for generating a binary mask. However, the output of the model is just four bounding boxes and the picture's probability of being tampered with. Which phase during the training pipeline should I use to generate the probability map?

No bounding boxes?

I was able to successfully train on 50,000 iterations, but when I run the demo_two_stream.py, the output in layer_utils doesn't have any bounding boxes.

PDB issue

This is the full output if I delete the pdb.trace() line:

Traceback (most recent call last):
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1322, in _do_call
return fn(*args)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1307, in _run_fn
options, feed_dict, fetch_list, target_list, run_metadata)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1409, in _call_tf_sessionrun
run_metadata)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Incompatible shapes: [256,8] vs. [0,8]
[[Node: gradients/loss_default/mul_9_grad/Mul_1 = Mul[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"](gradients/loss_default/Sum_1_grad/Tile, vgg_16/rpn_rois/PyFunc/_157)]]
[[Node: loss_default/add_4/_191 = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_1948_loss_default/add_4", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "train.py", line 222, in
train.train()
File "train.py", line 164, in train
sess, blobs, train_op)
File "/home/ubuntu/Image_manipulation_detection/lib/nets/network.py", line 366, in train_step
feed_dict=feed_dict)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 900, in run
run_metadata_ptr)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1135, in _run
feed_dict_tensor, options, run_metadata)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1316, in _do_run
run_metadata)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1335, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Incompatible shapes: [256,8] vs. [0,8]
[[Node: gradients/loss_default/mul_9_grad/Mul_1 = Mul[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"](gradients/loss_default/Sum_1_grad/Tile, vgg_16/rpn_rois/PyFunc/_157)]]
[[Node: loss_default/add_4/_191 = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_1948_loss_default/add_4", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]]

Caused by op 'gradients/loss_default/mul_9_grad/Mul_1', defined at:
File "train.py", line 222, in
train.train()
File "train.py", line 92, in train
gvs = optimizer.compute_gradients(loss)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/training/optimizer.py", line 526, in compute_gradients
colocate_gradients_with_ops=colocate_gradients_with_ops)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/gradients_impl.py", line 494, in gradients
gate_gradients, aggregation_method, stop_gradients)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/gradients_impl.py", line 636, in _GradientsHelper
lambda: grad_fn(op, *out_grads))
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/gradients_impl.py", line 385, in _MaybeCompile
return grad_fn() # Exit early
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/gradients_impl.py", line 636, in
lambda: grad_fn(op, *out_grads))
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/math_grad.py", line 870, in _MulGrad
return gen_math_ops.mul(grad, y), gen_math_ops.mul(grad, x)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/gen_math_ops.py", line 4759, in mul
"Mul", x=x, y=y, name=name)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3392, in create_op
op_def=op_def)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1718, in init
self._traceback = self._graph._extract_stack() # pylint: disable=protected-access

...which was originally created as op 'loss_default/mul_9', defined at:
File "train.py", line 222, in
train.train()
File "train.py", line 86, in train
layers = self.net.create_architecture(sess, "TRAIN", self.imdb.num_classes, tag='default')
File "/home/ubuntu/Image_manipulation_detection/lib/nets/network.py", line 305, in create_architecture
self._add_losses()
File "/home/ubuntu/Image_manipulation_detection/lib/nets/network.py", line 242, in _add_losses
loss_box = self._smooth_l1_loss(bbox_pred, bbox_targets, bbox_inside_weights, bbox_outside_weights)
File "/home/ubuntu/Image_manipulation_detection/lib/nets/network.py", line 201, in _smooth_l1_loss
out_loss_box = bbox_outside_weights * in_loss_box
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py", line 979, in binary_op_wrapper
return func(x, y, name=name)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py", line 1211, in _mul_dispatch
return gen_math_ops.mul(x, y, name=name)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/gen_math_ops.py", line 4759, in mul
"Mul", x=x, y=y, name=name)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3392, in create_op
op_def=op_def)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1718, in init
self._traceback = self._graph._extract_stack() # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): Incompatible shapes: [256,8] vs. [0,8]
[[Node: gradients/loss_default/mul_9_grad/Mul_1 = Mul[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"](gradients/loss_default/Sum_1_grad/Tile, vgg_16/rpn_rois/PyFunc/_157)]]
[[Node: loss_default/add_4/_191 = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_1948_loss_default/add_4", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]]

模型下载?

您好,能否提供 vgg16_faster_rcnn_iter_5000 的下载地址?

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.