How to convert images into a dataset for semantic segmentation - neural-network

I am trying to make a new semantic segmentation model that will take grainy microscopy images as input and segment them.
I have all the input and ground truth images in .png format, and I'm having a hard time curating them into a dataset that others can use. I've looked into some articles, but they explain how to make label images that I already have. So, is there a way/software which I can use to curate the dataset?
Thanks

You can also use the open-source tool, FiftyOne, to curate the dataset in a way that allows you to share it and also easily visualize, explore, and analyze it along with any future model predictions.
FiftyOne has a Python API that will load your instance or semantic segmentation labels into a FiftyOne Dataset which you can then query and visualize in the App (both the raw images and the annotations).
If you store your images and segmentations on disk in this file structure:
segmentation_dataset
|
|
+--- data
| |
| +--- 000.png
| +--- 001.png
| +--- 000.png
| ...
|
+--- labels
|
+--- 000.png
+--- 001.png
+--- 000.png
...
Then you can load it into Python and visualize it with these lines of code:
import fiftyone as fo
dataset = fo.Dataset.from_dir(
"segmentation_dataset",
dataset_type=fo.types.ImageSegmentationDirectory,
name="segmentation_dataset",
force_grayscale=True,
)
# Visualize the dataset in your browser
session = fo.launch_app(dataset)
Note: Use the force_grayscale argument to load RGB masks like the one you provided.
Sharing the dataset
You can add and modify samples and labels on your dataset with the FiftyOne API and then export it to disk in a variety of formats (VOC, COCO, YOLO, CVAT, etc). From there you can zip it and let others easily load it back into FiftyOne.
For example, we can use the FiftyOneDataset format as it works for any label type:
dataset.export(
export_dir="/path/to/export_dir",
dataset_type=fo.types.FiftyOneDataset
)
Zip the dataset and send it to someone else, they can now run:
import fiftyone as fo
dataset = fo.Dataset.from_dir(
dataset_dir="/path/to/unzipped_dataset",
dataset_type=fo.types.FiftyOneDataset,
)
Splits
If you store splits of data in the folder structure shown below:
segmentation_dataset
|
|
+--- Train
| |
| +--- data
| | |
| | +--- 000.png
| | +--- 001.png
| | +--- 000.png
| | ...
| |
| +--- labels
| |
| +--- 000.png
| +--- 001.png
| +--- 000.png
| ...
+--- Test
| |
| ...
...
You can then load all of the samples into a dataset and add a tag to each one denoting which split it belongs to.
import fiftyone as fo
dataset_type = fo.types.ImageSegmentationDirectory
dataset = fo.Dataset.from_dir(
dataset_dir="segmentation_dataset/Train",
dataset_type=dataset_type,
tags="train",
name="segmentation_dataset",
)
dataset.add_dir(
dataset_dir="segmentation_dataset/Test",
dataset_type=dataset_type,
tags="test",
)
Training a model
From there, you can use this dataset directly to train a model (for example with PyTorch or PyTorch Lightning Flash)

You can organize the images along similar to the organization in the VOC challenge.
That is, you should have the following directory tree:
my_dataset
|
+--- InputImages
| |
| +--- 000.png
| +--- 001.png
| +--- 002.png
| ...
|
+--- SegmentationMasks
| |
| +--- 000.png
| +--- 001.png
| +--- 002.png
| ...
|
+--- ImageSets
|
+--- train.txt
+--- val.txt
+--- test.txt
That is, you store all input images under InputImages folder and all the segmentation masks you have under SegmentationMasks folder. Make sure the mask SegmentationMasks/000.png corresponds to InputImages/000.png (and so on for all images and masks).
Additionally, you can have a fixed split of your dataset into "train", "validation" and "test" sets. This split is stored in the test files under ImageSets:
The file train.txt lists the image ids that are part of the train set, val.txt lists the ids of the validation set and so on.
Make sure all ids are included in the split, and no image appears in two splits.
(That is, the union of "train.txt" + "val.txt" + "test.txt" = all ids, and the intersection is empty).

Related

Does SQL have a way to group rows without squashing the group into a single row?

I want to do a single query that outputs an array of arrays of table rows. Think along the lines of <table><rowgroup><tr><tr><tr><rowgroup><tr><tr>. Is SQL capable of this? (specifically, as implemented in MariaDB, though migration to AWS RDS might occur one day)
The GROUP BY statement alone does not do this, it creates one row per group.
Here's an example of what I'm thinking of…
SELECT * FROM memes;
+------------+----------+
| file_name | file_ext |
+------------+----------+
| kittens | jpeg |
| puppies | gif |
| cats | jpeg |
| doggos | mp4 |
| horses | gif |
| chickens | gif |
| ducks | jpeg |
+------------+----------+
SELECT * FROM memes GROUP BY file_ext WITHOUT COLLAPSING GROUPS;
+------------+----------+
| file_name | file_ext |
+------------+----------+
| kittens | jpeg |
| cats | jpeg |
| ducks | jpeg |
+------------+----------+
| puppies | gif |
| horses | gif |
| chickens | gif |
+------------+----------+
| doggos | mp4 |
+------------+----------+
I've been using MySQL for ~20 years and have not come across this functionality before but maybe I've just been looking in the wrong place ¯\_(ツ)_/¯
I haven't seen an array rendering such as the one you want, but you can simulate it with multiple GROUP BY / GROUP_CONCAT() clauses.
For example:
select concat('[', group_concat(g), ']') as a
from (
select concat('[', group_concat(file_name), ']') as g
from memes
group by file_ext
) x
Result:
a
---------------------------------------------------------
[[puppies,horses,chickens],[kittens,cats,ducks],[doggos]]
See running example at DB Fiddle.
You can tweak the delimiters such as ,, [, and ].
SELECT ... ORDER BY file_ext will come close to your second output.
Using GROUP BY ... WITH ROLLUP would let you do subtotals under each group, which is not what you wanted either, but it would give you extra lines where you want the breaks.

java.lang.NoSuchMethodError: breeze.linalg.tile$.tile_DM_Impl2

I have a spark code that use breeze. I can se the breeze version of my project:
$ gradle dependencies | grep breeze
| | +--- org.scalanlp:breeze_2.11:0.12
| | | +--- org.scalanlp:breeze-macros_2.11:0.12
+--- org.scalanlp:breeze_2.11:0.12 (*)
| | +--- org.scalanlp:breeze_2.11:0.12
| | | +--- org.scalanlp:breeze-macros_2.11:0.12
+--- org.scalanlp:breeze_2.11:0.12 (*)
| | +--- org.scalanlp:breeze_2.11:0.12
| | | +--- org.scalanlp:breeze-macros_2.11:0.12
+--- org.scalanlp:breeze_2.11:0.12 (*)
| | | +--- org.scalanlp:breeze_2.11:0.12
| | | | +--- org.scalanlp:breeze-macros_2.11:0.12
| +--- org.scalanlp:breeze_2.11:0.12 (*)
| | | +--- org.scalanlp:breeze_2.11:0.12
| | | | +--- org.scalanlp:breeze-macros_2.11:0.12
| +--- org.scalanlp:breeze_2.11:0.12 (*)
The version of breeze included in spark 2.1.1 is 0.12. I can see this looking in the spark jars directory:
spark-2.1.1-bin-hadoop2.4$ find . -name *.jar | grep breeze
./jars/breeze_2.11-0.12.jar
./jars/breeze-macros_2.11-0.12.jar
But when I submit the job to spark (even local) I get this error:
java.lang.NoSuchMethodError: breeze.linalg.tile$.tile_DM_Impl2(Lscala/reflect/ClassTag;Lbreeze/storage/Zero;Lbreeze/generic/UFunc$InPlaceImpl2;)Lbreeze/generic/UFunc$UImpl2;
at mypackage.MyClass.calcOne(MyClass.scala:51)
at mypackage.MyClass$$anonfun$1.apply(MyClass.scala:36)
at mypackage.MyClass$$anonfun$1.apply(MyClass.scala:35)
at scala.collection.Iterator$$anon$11.next(Iterator.scala:409)
at scala.collection.Iterator$class.foreach(Iterator.scala:893)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1336)
at scala.collection.TraversableOnce$class.foldLeft(TraversableOnce.scala:157)
at scala.collection.AbstractIterator.foldLeft(Iterator.scala:1336)
at scala.collection.TraversableOnce$class.fold(TraversableOnce.scala:212)
at scala.collection.AbstractIterator.fold(Iterator.scala:1336)
at org.apache.spark.rdd.RDD$$anonfun$fold$1$$anonfun$20.apply(RDD.scala:1044)
The command line used:
spark-2.1.1-bin-hadoop2.4/bin/spark-submit --class my.Main myjar.jar
Found the problem:
My SPARK_HOME environment variable was setting to an old spark version.
So bin/spark-class was looking for jars dependencies in this other path

In emacs org mode, is there a formula I can use to count the number of cells?

I'm new to emacs (spacemacs, actually) and org-mode. I'd like to have a final line in my table that shows how many rows there are in the table. Is there a formula function for that?
This formula should work: vlen(#I..#II).
Example:
| Title |
|-------|
| one |
| two |
| three |
| four |
|-------|
| 4 |
#+Tblfm: #6$1=vlen(#I..#II)
the example above is specified as "#6" which requires you to know hte sum in advance. The following seems to work:
| Title |
|-------|
| one |
| two |
| three |
| four |
|-------|
| 4 |
#+Tblfm: #II$1=vlen(#I..#II)

How to present data in a tree like table in UI5

I have data which is expected to be displayed in a structured table. It is expected that the table can be opened and collapsed on two levels allowing
you to drill down in the data.
Example: Cities World Wide
When the table is loaded it should be displayed like this:
Area | Country | Name | Population | ...
--------------+----------------+-------------+-------------+----
Europe | | | |
North America | | | |
... | | | |
when I click on "Europe" the second level is shown:
Area | Country | Name | Population | ...
--------------+----------------+-------------+-------------+-----
Europe | | | |
| Germany | | |
| Czech Republic | | |
North America | | | |
... | | | |
When I now click on "Germany" the third level containing the actual city data is shown:
Area | Country | Name | Population | ...
--------------+----------------+-------------+-------------+-----
Europe | | | |
| Germany | | |
| | Berlin | 4 Million | ...
| | Leipzig | 0.5 Million | ...
| Czech Republic | | |
North America | | | |
... | | | |
How can I achieve a drill down in a tree like structure like shown in this example in UI5?
Since one of the requirement is to also to see and compare the data at once I believe a table control would be best but I don't know how to bring in this drill down behavior.
Mobile support is not required. The person using this will be a data analyst working on a big screen.
Any help appreciated.
While writing this question I came up with the search phrase "ui5 tree table" and voila:
https://experience.sap.com/fiori-design-web/ui-components/tree-table/
This is what I was looking for.

What is the best way to "paginate" a loooong SVG file on iOS?

I am facing an interesting problem with SVG and iOS.
I need to render very long SVG files (up to about 5mb large), which hasn't been a problem using UIWebView. I also haven't had a problem scrolling them smoothly with JS, but since I'm waiting on my developer program application to be approved I haven't tested the performance on an actual device.
I'm now trying to achieve a page-turning effect like how the iBooks app flips pages. It doesn't have to be as elaborate and intricate, the gist of the idea is that the next section of the svg will "wipe over" the last.
Reason being, I need both "pages" of content to remain static to ease the reading of the content during the "flipping" process. Scrolling very quickly makes the contents of the SVG difficult to read.
Here is a graphic representation of what I would like to achieve:
---------------------------
| |
| |
| |
| 1 |
| |
| |
| |
| |
---------------------------
---------------------------
| | |
| | |
| | |
| 2 | 1 |
| |-> |
| | |
| / |
| / |
---------------------------
---------------------------
| | |
| | |
| | |
| 2 | 1 |
| |-> |
| | |
| / |
| / |
---------------------------
---------------------------
| |
| |
| |
| 2 |
| |
| |
| |
| |
---------------------------
Looking forward to some interesting ideas from you veterans!
I haven't rut to such needs, but from what I know, it could be made by two UIViews (or any of their subclasses). All you have to do is a custom animation on flip(a simple one if you interested in flip only, a harder one if you need the animation actually to go one with the finger). And of course you'll need to put corresponding part of your file to those views. Actually I would suggest using 3 views, so you'll be able to put content of the next "page" while it still offscreen. That will make your animation smoother.