use tensorflow classify_image.py to classfy png image - tensorflow

I want to use tensorflow/models/tutorials/image/imagenet/classify_image.py to classify image, but it only support JPEG image. How can I do to use it to classify my image include JPEG and PNG format?

Related

Grayscale input image for SSD detector in Tensorflow Detection API

I'm creating a dataset of images to train a detector using Tensoflow Detection API (SSD/MobileNet).
Images are grayscale but it seems the input should be RGB image.
Do I need to convert grayscale images to a three channel RGB by just copying first channel to two other channels? (If yes, is there any software for doing this?) or Two other channel should be empty? (Is there any software for doing this?)
Best regards.
Yes, you have to convert your grayscale images to RGB images.
A possible solution is to use OpenCV:
import cv2
# suppose that gray_img is your grayscale image
input = cv2.cvtColor(gray_img, cv2.COLOR_GRAY2RGB)
Now you can use input as a valid input image for your model

change the input image size for mobilenet_ssd using tensorflow

I am using tensorflow and tflite to detect object. The model I use is mobilenet_ssd (version 2) from https://github.com/tensorflow/models/tree/master/research/object_detection
the input image size for detection is fixed 300*300, which is hard-coded in the model.
I want to input 1280*720 image for detection, how to do this? I do not have the traing image dataset of resolution 1280*720. I only have pascal and coco dataset.
How to modify the model to accept 1280*720 image(do not scale the image) for detection?
To change the input size of the image, you need to redesign the anchor box position. Because the anchors are fixed to the input image resolution. Once you change the anchor positions to 720P, then the mobilenet can accept 720p as input.
The common practice is scaling the input image before feeding the data into TensorFlow / TensorFlow Lite.
Note: The image in the training data set aren't 300*300 originally. The original resolution may be bigger and non-square, and it's downscaled to 300*300. It means it's totally fine to downscale 1280*720 image to 300*300 image and it should work fine.
Do you mind to try scaling and see if it works?

Why put the whole image in a tfrecord file? Why not just crop according to the bounding-box and put the cropped object in the tfrecord file?

Why do we put the whole image in a tfrecord file? Why not just crop the image according to the bounding-box and put the cropped object in the tfrecord file? This should greatly reduce the size of that file.
Because you want to learn to detect where that object is in the image. In image classification, you would cut out the images as you proposed and the network would output "car" or "not car". In object detection, the network will output the bounding boxes for the objects along with the class. ("car is at x1-x2-y1-y2") It learns by having the whole picture with the bounding boxes for the loss function.

matplotlib changing bitmap color mapping

I'm using matplotlib to generate some composite figures (from raw data and images). I'm trying to get the script to take image files of a few file formats, which are then plotted via:
Nxy = mpimg.imread(Nxy_filename)
imgplot = ax1.imshow(Nxy)
where ax1 is the subplot I want the image to show up in. This works fine for both PNG and JPEG images, but for a .bmp (of the same image) matplotlib seems to turn it blue, i.e.
turns into:
in my composite figure. On the other hand, the png and jpg files look exactly the same as the original. Any idea why this would happen? I'm reluctant to blindly alter the color map in the code since the other image formats appear as expected.
It sounds like your PNG and JPEG images are RGB images that happen to be grey while the BMP image is grey scale. Check the shape of Nxy. My guess is it's two dimensional for the BMP while the PNG and JPEG image arrays have three dimensions.

ImageMagick GrayScale

How to convert image to grayscale with ImageMagick in objective-c? I load images to imageMagick and use them as OpenGL textures. I need to make image grayscale on load. I mean make grayscale subImage of original image
Not sure if this is what you're asking for, but you can find some logic to convert to Grayscale here.
Similar info is available in this GoogleGroups Posting.