Can I save the output images of TensorFlow Objectdetection API in a folder? - tensorflow

I am new to object detection.
Can I save the output images of my tensorflow object detection API in a folder after detection is completed in the Jupyter notebook?
It was intuitive to right click and save the images when detecting a few images, but it is impractical to do same when I have over 1000 images to run detection on.
is the output already stored in a subfolder that I am unaware of??
Can I store the output in a folder or directory?
Any suggestions will be appreciated.
I have checked differnt means but found nothing helpful
this is what my detection cell looks like
Thanks

Use PIL you can save your image to disk. First you import the module
from PIL import Image
And then you can comment out the plot lines, add the save lines.
#plt.figure(figsize=IMAGE_SIZE)
#plt.imshow(image_np)
#save to same folder as data input
img = Image.fromarray(image_np)
img.save(image_path[:-4]+'output_'+'.png')

Related

Further question on "insert image in Google colab text cell"

I followed the question and answers to question on inserting images into Colab text cells. Similar to that poster, I wish to place images into text cells rather than bring them up using Python code cells.
The source of the images is intended to be files in a subfolder of the project containing the Jupyter notebook whose discussion I want to enrich with photos and drawings. It is important to keep the notebook and supporting files, including images and data, in a single encompassing folder. (I expect to work on dozens of such projects, each with its own assembly of files in separate project folders.)
In order to achieve this I mounted the Google drive containing the image files by running
from google.colab import drive
drive.mount('/content/drive')
I clicked on the file folder in the left sidebar and expanded directories until I could select the image file I want to use and obtain its path. Then I tried using either of the following in a text cell:
<img src="/content/drive/MyDrive/Colab Notebooks/Lab13 Mechanisms/Figures/PantographCloseUp.JPG" alt="Close up of a pantograph made with LEGO Technics and LEGO Mindstorms components">
![Close up of a pantograph made with LEGO Technics and LEGO Mindstorms components](/content/drive/MyDrive/Colab%20Notebooks/Lab13%20Mechanisms/Figures/PantographCloseUp.JPG)
Neither of these work: no image appears. Right clicking on the empty box containing a question mark and choosing inspect element and then the tab "sources", I clicked on the image resource and got "Failed to load resource: the server responded with a states of 403 ()." I understand this is some sort of authorization fault (???).
(The image is set to be shared with anyone with the link.)
What is going on? Why don't the image-in-text-cell methods work using the file paths on the mounted drive? (Ideally, too, I would like to use a relative path: Figures/PantographCloseUp.JPG)
Please note that the following does produce an image in a text cell but is not a terribly convenient way of keeping track of image sources:
<img src='https://drive.google.com/uc?id=1dYjA01xQqah0l2cSQYcd6U0UFrfH3LPK'/>
Also, I can run code to display the image using the desired file path but this is also not convenient because a user (a student) of the document would have to run all of these cells just to look at the pictures.
from IPython.display import Image
Image("/content/drive/MyDrive/Colab Notebooks/Lab13 Mechanisms/Figures/PantographCloseUp.JPG")

How does one create a custom dataset of images with masks for image segmentation?(specifically for Tensorflow)

Every tutorial I find involves using a pre-made, but the project I'm trying to do is image segmentation on pictures if playing cards. The dataset will be one I create but I'm finding little to no resources about creating the dataset and needed image masks. Any help would be great!
I use Gimp (https://www.gimp.org/) with layers. You can use several useful tools, such as the "BucketFill", to quickly color a region. Then you just have to export the layers to a new file to obtain the mask. VGG image annotator is also useful (https://www.robots.ox.ac.uk/~vgg/software/via/via-1.0.6.html)
For 3D images you can use VTK and ITKsnap (http://www.itksnap.org/pmwiki/pmwiki.php) for volume identification, visualization and exporting. MIPAV (https://mipav.cit.nih.gov/) is also useful.
VGG Image Annotator (VIA), here is a quick demo. There is also labelme

How to get labels for ILSVRC2012 Classification Task

The ILSVRC 2012 small classification dataset is not separated by folder and don't have a labels file. How get the labels for the training set?
I tried on nonpub downloads page but does not exist anymore, and i tried by the filenames but their don't have the synset id on it.
I've been having the same issue today following this tutorial on reproducing ImageNet Validation results. I think I've found an answer, even if partial
In the article they point out to this link to get the validation set for object detection. I downloaded it and had the same issue as yourself, it only contains images without labels. What I've found is that this same website had this other link for the bounding boxes. I've downloaded it and alongside with the bboxes it comes with the proper class for each image
Hope this helps!

Extracting embedded PNG byte streams from PDF

I am programming in Python, but if some tool/library exists in another language that would help me considerably, I am open to suggestions.
I have a large collection of pdf pages that live in a database, and I am trying to automate the collection of those pages to build some image recognition models with them.
These "pdfs" are actually just PNG images encased with a PDF wrapper (presumably so they can be read by PDF readers like Adobe Acrobat). I need the pdfs in image format to feed into the image recognition model pipeline. I am assuming they are PNG images, because when I save the images from the browser (i.e., right click and save image as), the resulting file is a PNG file.
After reading this question from 2010, and checking out this blog post from 2007, I've concluded that there must be a way to just extract the PNG byte array from the PDF instead of re-converting the PDF into a new image. Oddly though, I couldn't find the PNG file header with
#Python 3.6
header = bytes([137, 80, 78, 71, 13, 10, 26, 10])
#the resulting header looks like this: b'\x89PNG\r\n\x1a\n'
file.find(header)
Does that mean that the embedded image is not in fact a PNG image?
If there is no easy way to extract the embedded image byte array, what tool might I use to automate the conversion of each PDF file to some image format (preferably JPEG, PNG, or TIFF)?
Edit: I know tools like ImageMagick exist for format conversions, but I'd really rather do the extraction method for the sake of learning more about these file formats.
pip install pdf2image
pip install pillow
pip install numpy
pip install opencv-python
Then,
import numpy as np
from pdf2image import convert_from_path as read
import PIL
import cv2
#pdf in the form of numpy array to play around with in OpenCV or PIL
img = np.asarray(read('path to the pdf file')[0])#first page of pdf
cv2.imwrite('path to save the image with the file extension',img)

How to display filters in tensorboard

I have a simple MNIST model from the tensorflow tutorial. I want to see how the first convolutional layer's filters changes with time. When I use tf.summary.image, only one of the steps is displayed, and the rest is ignored. Is there any way to work this around?
TF does not have videos, but you can generate image at each step, save them in some directory and then create a video from them.