Skip to content

Commit 474b514

Browse files
committed
classification train
1 parent 542a8fd commit 474b514

25 files changed

+123
-208
lines changed

docs/Makefile

100644100755
File mode changed.

docs/README.md

100644100755
File mode changed.

docs/make.bat

100644100755
File mode changed.

docs/requirements.txt

100644100755
File mode changed.
Loading

docs/source/api/api.rst

100644100755
File mode changed.

docs/source/api/torchsat.datasets.rst

100644100755
File mode changed.

docs/source/api/torchsat.models.classification.rst

100644100755
File mode changed.

docs/source/api/torchsat.models.detection.rst

100644100755
File mode changed.

docs/source/api/torchsat.models.rst

100644100755
File mode changed.

docs/source/api/torchsat.models.segmentation.rst

100644100755
File mode changed.

docs/source/api/torchsat.rst

100644100755
File mode changed.

docs/source/api/torchsat.transforms.rst

100644100755
File mode changed.

docs/source/api/torchsat.utils.rst

100644100755
File mode changed.

docs/source/conf.py

100644100755
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
'sphinx.ext.intersphinx',
3434
'sphinx.ext.todo',
3535
'sphinx.ext.coverage',
36-
'sphinx.ext.mathjax'
36+
'sphinx.ext.mathjax',
37+
'recommonmark'
3738
]
3839

3940
# Add any paths that contain templates here, relative to this directory.
@@ -44,6 +45,10 @@
4445
# This pattern also affects html_static_path and html_extra_path.
4546
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
4647

48+
source_suffix = {
49+
'.rst': 'restructuredtext',
50+
'.md': 'markdown',
51+
}
4752

4853
# -- Options for HTML output -------------------------------------------------
4954

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
1-
Core Conceptions
2-
================
1+
# Core Conceptions
2+
33
Because TorchSat is based on PyTorch,
44
you'd better have some deep learning and PyTorch knowledge to use and modify this project.
55

66
Here are some core conceptions you should know.
77

8-
1. All input image data, Whether it is PNG, JPEG or GeoTIFF, will be converted to NumPy_ ndarray,
9-
and the ndarray dimension is ``[height, width]`` (single channel image) or ``[height, width, channels]`` (multi-channel image).
8+
1. All input image data, Whether it is PNG, JPEG or GeoTIFF, will be converted to [NumPy](https://numpy.org/) ndarray,
9+
and the ndarray dimension is `[height, width]` (single channel image) or `[height, width, channels]` (multi-channel image).
1010

11-
2. After the data is read into NumPy_ ndarray, there are only three data types, `np.uint8`, `np.uint16`, `np.float`.
11+
2. After the data is read into [NumPy](https://en.wikipedia.org/wiki/Normalized_difference_vegetation_index) ndarray, there are only three data types, `np.uint8`, `np.uint16`, `np.float`.
1212
These three data types are chosen because, in satellite imagery,
1313
- The most common image stored in JPEG or PNG (such as the Google Map Satellite Image) is mostly `8-bit (np.uint8)` data;
1414
- And the `16-bit (np.uint16)` is mostly the original data type of remote sensing satellite imagery, which is also very common;
1515
- The third type `float (np.float)` is considered, because sometimes, we will use remote sensing index (such as NDVI_) as features to participate in training. For this data we suppose all input data values range from 0 to 1.
16-
17-
18-
19-
.. _NumPy: https://numpy.org/
20-
.. _NDVI: https://en.wikipedia.org/wiki/Normalized_difference_vegetation_index

docs/source/index.rst

100644100755
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ TorchSat is an open-source deep learning framework for satellite imagery analysi
2222
:maxdepth: 2
2323
:caption: Contents:
2424

25-
installation.rst
26-
core-conception.rst
25+
installation.md
26+
core-conception.md
2727
quickstart.rst
28-
tutorials.rst
28+
tutorials/image_classification.md
2929
api/api.rst
3030

3131

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,44 @@
1-
Installation
2-
=============
3-
Deepndencies
4-
------------
1+
# Installation
2+
## Deepndencies
53

6-
TorchSat is based on `PyTorch`_, so you should install the PyTorch
4+
TorchSat is based on [PyTorch](https://pytorch.org/), so you should install the PyTorch
75
first. And if you want to use the GPU version, you should install CUDA.
86

97
Python package dependencies(seee also requirements.txt): pytorch,
108
torchvision, numpy, pillow, tifffile, six, scipy, opencv
119

12-
Note: TorchSat only suport `Python 3`_. We recommend version after
10+
>Note: TorchSat only suport [Python 3](https://www.python.org/). We recommend version after
1311
Python 3.5(including python 3.5), but wo have not tested any version
1412
below Python 3.5
1513

16-
Install
14+
## Install
1715
-------
1816

19-
Install from PyPI or Anconda
20-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17+
### Install from PyPI
2118

2219
- PyPI: ``pip3 install torchsat``
23-
- Anconda: `` ``
2420

25-
Install from source
26-
~~~~~~~~~~~~~~~~~~~
21+
### Install from source
2722

2823
- Install the latest version
2924

30-
.. code:: bash
25+
```
3126
3227
git clone https://github.com/sshuair/torchsat.git
3328
cd torchsat
3429
python3 setup.py install
30+
```
3531

3632
- Install the stable version
3733

38-
1. Visit the `release`_ page and download the version you want.
34+
1. Visit the [release](https://github.com/sshuair/torchsat/releases) page and download the version you want.
3935
2. Decompress the zip or tar file.
4036
3. Enter the torchsat directory and run this command
4137
``python3 setup.py install``.
4238

43-
For data preparation
44-
--------------------
4539

46-
[wip]
47-
48-
49-
Docker
50-
------
51-
You can pull the docker image from `Docker Hub`_ if you want use TorchSat in docker.
40+
### Docker
41+
You can pull the docker image from [Docker Hub](https://hub.docker.com/r/sshuair/torchsat) if you want use TorchSat in docker.
5242

5343
1. pull image
5444
- cpu: `docker pull sshuair/torchsat:cpu-latest`
@@ -61,9 +51,3 @@ You can pull the docker image from `Docker Hub`_ if you want use TorchSat in doc
6151

6252
This way you can easily use the TorchSat in docker container.
6353

64-
65-
66-
.. _PyTorch: https://pytorch.org/
67-
.. _Python 3: https://www.python.org/
68-
.. _release: https://github.com/sshuair/torchsat/releases
69-
.. _Docker Hub: https://hub.docker.com/r/sshuair/torchsat

docs/source/issues.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
1. clip vector error
3+
- description
4+
```
5+
/usr/local/lib/python3.6/site-packages/geopandas/base.py:76: UserWarning: Cannot generate spatial index: Missing package `rtree`.
6+
warn("Cannot generate spatial index: Missing package `rtree`.")
7+
Traceback (most recent call last):
8+
File "script.py", line 17, in <module>
9+
res_union = gpd.overlay(df1, df2, how='union')
10+
File "/usr/local/lib/python3.6/site-packages/geopandas/tools/overlay.py", line 371, in overlay
11+
result = _overlay_union(df1, df2)
12+
File "/usr/local/lib/python3.6/site-packages/geopandas/tools/overlay.py", line 298, in _overlay_union
13+
dfinter = _overlay_intersection(df1, df2)
14+
File "/usr/local/lib/python3.6/site-packages/geopandas/tools/overlay.py", line 212, in _overlay_intersection
15+
sidx = bbox.apply(lambda x: list(spatial_index.intersection(x)))
16+
File "/usr/local/lib/python3.6/site-packages/pandas/core/series.py", line 3194, in apply
17+
mapped = lib.map_infer(values, f, convert=convert_dtype)
18+
File "pandas/_libs/src/inference.pyx", line 1472, in pandas._libs.lib.map_infer
19+
File "/usr/local/lib/python3.6/site-packages/geopandas/tools/overlay.py", line 212, in <lambda>
20+
sidx = bbox.apply(lambda x: list(spatial_index.intersection(x)))
21+
AttributeError: 'NoneType' object has no attribute 'intersection'
22+
```
23+
24+
- solution: you should install the rtree
25+
for macos: brew install spatialindex && pip3 install rtree
File renamed without changes.

docs/source/tutorials.rst

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Image Classification
2+
3+
This is classification turtorial for satellite image. We will use sentinal-2 TCI data as an example. It cover from training data prepare, train the model, and predict the new files.
4+
5+
## Prepare Trainning Data
6+
Suppose we got a scene of sentinel-2 satellite TCI image data. You can download from [esa scihub](https://scihub.copernicus.eu/dhus/#/home). I has got the secene id `T51RTQ_20200513T023551_TCI` and convert the JPEG2000 to GeoTIFF.
7+
8+
1. patch the large 10980x10980 pixel image to 128x128 pixel image
9+
10+
```
11+
12+
➜ cd tests/classification/
13+
➜ ts make-mask-cls --filepath T51RTQ_20200513T023551_TCI.tif --width 128 --height 128 --outpath ./patched
14+
processing 1/1 file T51RTQ_20200513T023551_TCI.tif ...
15+
14%|███████████████▉ | 12/85 [00:07<00:45, 1.60it/s]
16+
```
17+
You should get the following data:
18+
19+
![](../_static/img/turotial/classification_patch.png)
20+
21+
2. **labeling the train data and test data**
22+
23+
You can split the data into tran data and test data as below. And then labeling those patched image into four classes: `water`, `residential`, `farmland`, `forest`. Reorganize the catalog of these small images according to different categories and split them to train and validation dataset.
24+
```
25+
.
26+
├── train
27+
│ ├── water
28+
│ │ ├── T51RTQ_20200513T023551_TCI_1_29.tif
29+
│ │ ├── T51RTQ_20200513T023551_TCI_2_29.tif
30+
│ │ ├── T51RTQ_20200513T023551_TCI_8_14.tif
31+
│ │ └── ...
32+
│ ├── frameland
33+
│ │ ├── T51RTQ_20200513T023551_TCI_3_2.tif
34+
│ │ ├── T51RTQ_20200513T023551_TCI_3_77.tif
35+
│ │ ├── T51RTQ_20200513T023551_TCI_11_1.tif
36+
│ │ └── ...
37+
│ ├── residential
38+
│ │ ├── T51RTQ_20200513T023551_TCI_0_29.tif
39+
│ │ ├── T51RTQ_20200513T023551_TCI_1_37.tif
40+
│ │ ├── T51RTQ_20200513T023551_TCI_4_36.tif
41+
│ │ └── ...
42+
│ ├── forest
43+
│ │ ├── T51RTQ_20200513T023551_TCI_7_21.tif
44+
│ │ ├── T51RTQ_20200513T023551_TCI_22_45.tif
45+
│ │ ├── T51RTQ_20200513T023551_TCI_41_29.tif
46+
│ │ └── ...
47+
├── validation
48+
│ ├── water
49+
│ │ ├── T51RTQ_20200513T023551_TCI_5_32.tif
50+
│ │ ├── T51RTQ_20200513T023551_TCI_5_12.tif
51+
│ │ ├── T51RTQ_20200513T023551_TCI_4_32.tif
52+
│ │ └── ...
53+
│ ├── frameland
54+
│ │ ├── T51RTQ_20200513T023551_TCI_9_2.tif
55+
│ │ ├── T51RTQ_20200513T023551_TCI_6_76.tif
56+
│ │ ├── T51RTQ_20200513T023551_TCI_2_5.tif
57+
│ │ └── ...
58+
│ ├── residential
59+
│ │ ├── T51RTQ_20200513T023551_TCI_8_29.tif
60+
│ │ ├── T51RTQ_20200513T023551_TCI_3_37.tif
61+
│ │ ├── T51RTQ_20200513T023551_TCI_2_36.tif
62+
│ │ └── ...
63+
│ ├── forest
64+
│ │ ├── T51RTQ_20200513T023551_TCI_8_12.tif
65+
│ │ ├── T51RTQ_20200513T023551_TCI_31_5.tif
66+
│ │ ├── T51RTQ_20200513T023551_TCI_29_29.tif
67+
│ │ └── ...
68+
```
69+
70+
## Train the model
71+
72+
test

tools/preprocessing/make_mask_cls.py

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)