Syn-McJ / TFClassify-Unity

An example of using Tensorflow with Unity for image classification and object detection.
MIT License
167 stars 47 forks source link

how to set the IMAGE_MEAN and IMAGE_STD in object-detection #45

Closed HolyShitKillingMachine closed 4 years ago

HolyShitKillingMachine commented 4 years ago

Hello ,i'm back again. been using ssd mobile net to train my model,but don't know how to set the valve of the IMAGE_MEAN and IMAGE_STD. the image_mean's valve change may cause huge difference.

ssd-v1 - 副本.txt

this is my training config.

Syn-McJ commented 4 years ago

@HolyShitKillingMachine,

You should infer IMAGE_MEAN and IMAGE_STD from the code you used for training your model.

Mean and std are used to normalize image pixels from the value range of [0:255] to something more suitable for deep learning model. The new range might be [-1:1] (in this case, mean and std are 127.5 and 127.5), or [0:1] (in this case mean/std are 0/255), or pixels might not be changed at all before feeding them to the model, in which case mean/std would be 0/1. The formula is new_pixel_value = (old_pixel_value - IMAGE_MEAN) / IMAGE_STD

You can try those options, but what you really need to do is to inspect your model training code (or inference code if it's available) and check how the image pixels were normalized.

HolyShitKillingMachine commented 4 years ago

@Syn-McJ yeah,i got it,but i still cann't find the code,in my opinion,the IMAGE_MEAN and IMAGE_STD should be 255 and 1 cause i just scale the image and do not have any other operations! so before the tensorflow,the image is just the cropped one here is my train.py train.txt generate_tfrecord.py generate_tfrecord.txt ssd-mobilenet-config ssd-v1.txt

hope you give me some advice!

HolyShitKillingMachine commented 4 years ago

@Syn-McJ the predict file Object_detection_image-ssd-mobilenet.txt the code that shows the image process

image = cv2.imread(PATH_TO_IMAGE) image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) image_expanded = np.expand_dims(image_rgb, axis=0)

I am a new one in the tensorflow and do not know what's done.

HolyShitKillingMachine commented 4 years ago

@Syn-McJ and the inference_graph code export_inference_graph.txt

HolyShitKillingMachine commented 4 years ago

After setting it to 0,1, and change your code to int value = Convert.ToInt32(classes[i, j]); var label = this.labels[value-1]; it works fine. hope it works well in android projector

Syn-McJ commented 4 years ago

@HolyShitKillingMachine Judging by that code, it does seem that pixels aren't normalized in your case, so 0,1 should be right. 255 and 1 are unlikely since that would mean that pixel values are normalized to [-255, 0] range which doesn't make much sense.

HolyShitKillingMachine commented 4 years ago

@Syn-McJ thanks,it works fine,and i will train more samples,i wanna get a better result.thanks for your help.