Repository: open-mmlab/mmdetection

Issue:
_pickle.PicklingError: Can't pickle <class 'numpy.core._exceptions.UFuncTypeError'>: it's not the same object as numpy.core._exceptions.UFuncTypeError
when i use 
dict(type='PhotoMetricDistortion',
         brightness_delta=32,
         contrast_range=(0.5, 1.5),
         saturation_range=(0.5, 1.5),
         hue_delta=18)
in config file for training

i got the following error:
Traceback (most recent call last):
  File "/usr/lib/python3.6/multiprocessing/queues.py", line 234, in _feed
    obj = _ForkingPickler.dumps(obj)
  File "/usr/lib/python3.6/multiprocessing/reduction.py", line 51, in dumps
    cls(buf, protocol).dump(obj)
_pickle.PicklingError: Can't pickle <class 'numpy.core._exceptions.UFuncTypeError'>: it's not the same object as numpy.core._exceptions.UFuncTypeError
that's all info.

i found the following code raise the error:
delta = random.uniform(-self.brightness_delta,self.brightness_delta)
img+=delta
in PhotoMetricDistortion class in pipelines/transforms.py file 
other familiar code raise the error too.
i don't know why?

i found if delta is negative or float,it will raise the error.positive integer is ok.


Discussion:
when i use  img = img + delta to replace img+=delta,it's ok...
Do you use the config [ssd300_coco.py](https://github.com/open-mmlab/mmdetection/blob/master/configs/ssd300_coco.py), I can't reproduce your error with this config. Could you specify which config you use and what modification you apply to? Could you provide more detail information about your environment?
when i use PhotoMetricDistortion in retinanet training, I met exactly same error
> Do you use the config ssd300_coco.py, I can't reproduce your error with this config. Could you specify which config you use and what modification you apply to? Could you provide more detail information about your environment?

I use the faster_rcnn_r50_fpn. torch-1.1.0, CUDA-10.1, numpy-1.18.2.Thanks. As mentioned above, when i replace '+=','*=',and such operation in PhotoMetricDistortion, the error disappear.
I found that the problem is that I didn't load image with float32=True, cv2.cvtColor doesn't support float64. That causes this wired error here:)
> > Do you use the config ssd300_coco.py, I can't reproduce your error with this config. Could you specify which config you use and what modification you apply to? Could you provide more detail information about your environment?
> 
> I use the faster_rcnn_r50_fpn. torch-1.1.0, CUDA-10.1, numpy-1.18.2.Thanks. As mentioned above, when i replace '+=','*=',and such operation in PhotoMetricDistortion, the error disappear.

@BChunlei  Just as @edwardyangxin  mentioned, when using PhotoMetricDistortion transformation, it is necessary to convert the image to np.float32 firstly just as what SSD does, you can refer [here](https://github.com/open-mmlab/mmdetection/blob/365c9302ee1eb5790b8e57f24ea4dfee8f2b88ac/configs/ssd300_coco.py#L51). But it is indeed not very friendly, would you like to create a PR to make it more friendly, i.e., report a reminder that user needs to set `to_float32` flag?

Resolving patch:
diff --git a/mmdet/datasets/pipelines/transforms.py b/mmdet/datasets/pipelines/transforms.py
--- a/mmdet/datasets/pipelines/transforms.py
+++ b/mmdet/datasets/pipelines/transforms.py
@@ -490,6 +490,9 @@ def __init__(self,
 
     def __call__(self, results):
         img = results['img']
+        assert img.dtype == np.float32, \
+            'PhotoMetricDistortion needs the input image of dtype np.float32,'\
+            ' please set "to_float32=True" in "LoadImageFromFile" pipeline'
         # random brightness
         if random.randint(2):
             delta = random.uniform(-self.brightness_delta,


Test patch: