Comments (7)
Update: The above problem was unrelated to loss_shape. I figured out through some trial and error that the format of the segmentation data must have a color index between 1-256 instead of RGB. Just updating this here in case someone is putting their own training data together. Though, it would be useful if there was a better descriptor of how this code uses loss_shape/how the loss function is working in here. Thanks!
from keras-fcn.
Could you elaborate on exactly the formats you're discussing here?
from keras-fcn.
Sure. I created training data using RGB .jpg format images that I downloaded from the web. I took the raw .jpg files, and using GIMP, created .jpg segmented images that were RGB format. I converted these to .png to match the format that the code was written to utilize. I then banged my head on my desk for a while until I thought to examine the image properties of the VOC2012 segmentation data and compare it to my own data. I found that while my segmentation data was RGB, the VOC segmentation data was Indexed color (256 colors). I wrote a short python script that read in the jpgs and converted to 256 colors .png files (below). I am currently training and on epoch 59/250. Not sure about success yet - but there it is. I do have concerns that when I converted from RGB to 256 colors I accidentally matched a color in the VOC data because I picked colors using RGB - I will be checking that next.
#script to batch convert to RGB .jpg images to .png 256 color images.
WD = "~/SegmentationObject/"
os.chdir(WD)
files = glob.glob ('*.jpg')
for infile in files:
file, ext = os.path.splitext(infile)
im = Image.open(infile).convert('P',colors=256)
im.save(file + ".png")
from keras-fcn.
Oh yeah that's a tricky one! For others reading, the png values are actually single channel ids, which are reused in Pascal VOC as class ids. What you see when you look at a png files are the values resulting from a lookup into what's known as a color palette
which is a map from id to a color.
jpg is a bit risky to use for segmentation data because it may change colors depending on compression settings, and thus identify a different class. I think python pillow can be used for format conversion and creating the palette.
from keras-fcn.
Yup! And, somewhat ironically, the .jpgs files I initially created were maximum quality and histograms of the colors showed my 3 distinct classes perfectly - but converting from .jpg to .png using PIL introduced new colors (for example, band 84 was cut into bands 83 and 84). As a work around, I managed to use quantize in PIL to convert my .jpgs to .pngs without loss (i.e. new colors) - but I have very little control over the class IDs and for palette I can only use an "adaptive" or "web" palette (see PIL readme). One major problem I also had was that two of my color classes were different enough in RGB that quantize converted my green and purple classes differently. I don't have any examples I can share, but with my green colored class, quantize combined the green colors with the VOID outline from VOC, but with my purple class, quantize kept the classes separate. In the end, I went back and manually recolored my images using the color select and bucket tools in GIMP. Another option would have been to convert into numpy format - but I wasn't sure how the COCO data was handled in the main code, and I didn't want to open a new can of worms.
Below is my new code I used to convert .jpg to .png:
`#convert to 3 color palette index
from PIL import Image
import glob, os
WD = "~/SegmentationObject/"
os.chdir(WD)
files = glob.glob ('*.jpg')
for infile in files:
file, ext = os.path.splitext(infile)
im = Image.open(infile).quantize(colors=3)
im.save(file + ".png")`
from keras-fcn.
Wow, thanks for the detailed explanation! I'm sure that will help someone out in the future.
from keras-fcn.
@bgr33r
Thank you very much for sharing you knowledge, I met this problem when I use this code for training 2 classes images.
from keras-fcn.
Related Issues (20)
- AttributeError: 'SegDirectoryIterator' object has no attribute 'next' HOT 14
- error when run "python data_pascal_voc.py pascal_voc_setup" HOT 2
- sparse_categorical_crossentropy vs binary_crossentropy_with_logits
- in resize_images_bilinear(X, height_factor, width_factor, target_height, target_width, data_format) TypeError: unsupported operand type(s) for *: 'NoneType' and 'int' HOT 4
- models.py HOT 2
- AttributeError: 'SegDirectoryIterator' object has no attribute 'next' HOT 4
- Comparison of models
- Dataset & start HOT 1
- Strange results from inference.py HOT 1
- reorganized for easier use
- checkpoint_weights.hdf5 ??? HOT 17
- could not read remote repository HOT 1
- I want to use my windows10 Ipython to run my datasets, but it shows an error : UnboundLocalError: local variable 'lr' referenced before assignment HOT 4
- Hello, I also have this problem, I want to train my data set, but the picture of my data set is jpg, the label is png, can I use this data set for training, if I can, I need the program What changes have been made, thank you HOT 1
- Unable to run 'train.py', the program ends directly
- Regarding the upsampling layer HOT 2
- ModuleNotFoundError: No module named 'tf_image_segmentation' HOT 3
- NameError: name 'transform_matrix_offset_center' is not defined HOT 2
- weights
- Inference gives black output
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from keras-fcn.