Comments (13)
Thanks for sharing the model and sample image!
I am not able to reproduce the misalignment issue. This is the output I get when I use your model to predict on the sample image:
This is the code I used (from the training and prediction tutorial notebooks), with RV v0.20.2:
import torch
import albumentations as A
from rastervision.core.data import PolygonVectorOutputConfig
from rastervision.pytorch_learner import SemanticSegmentationLearner
from rastervision.core.data import ClassConfig
from rastervision.pytorch_learner import SemanticSegmentationSlidingWindowGeoDataset
from rastervision.core.data import SemanticSegmentationLabels
model = torch.hub.load(
'AdeelH/pytorch-fpn:0.3',
'make_fpn_resnet',
name='resnet18',
fpn_type='panoptic',
num_classes=2,
fpn_channels=128,
in_channels=3,
out_size=(256, 256),
pretrained=True)
learner = SemanticSegmentationLearner.from_model_bundle(
model_bundle_uri='model/model-bundle.zip',
output_dir='debug-1773/',
model=model,
)
ds = SemanticSegmentationSlidingWindowGeoDataset.from_uris(
class_config=class_config,
image_uri='sample.tif',
size=256,
stride=256,
transform=A.Resize(256, 256))
predictions = learner.predict_dataset(
ds,
raw_out=True,
numpy_out=True,
predict_kw=dict(out_shape=(256, 256)),
progress_bar=True)
pred_labels = SemanticSegmentationLabels.from_predictions(
ds.windows,
predictions,
smooth=True,
extent=ds.scene.extent,
num_classes=len(class_config))
pred_labels.save(
uri='pred/',
crs_transformer=ds.scene.raster_source.crs_transformer,
class_config=class_config,
discrete_output=True,
smooth_output=False,
vector_outputs=[PolygonVectorOutputConfig(class_id=1, uri='pred/vector_output/class-1-polygons.json')]
)
That said, there does seem to be something off with the CRS in your sample TIFF. The above code throws a GDAL warning when reading from it. The warning can also be seen via gdalinfo
:
gdalinfo "sample.tif"
Warning 1: The definition of projected CRS EPSG:2363 got from GeoTIFF keys is not the same as the one from the EPSG registry, which may cause issues during reprojection operations. Set GTIFF_SRS_SOURCE configuration option to EPSG to use official parameters (overriding the ones from GeoTIFF keys), or to GEOKEYS to use custom values from GeoTIFF keys and drop the EPSG code.
Comparison of the CRS portion of the outputs of gdalinfo "sample.tif"
(right) with gdalsrsinfo "EPSG:2363"
(left) looks like so:
I think the diffs on lines 9, 28, and 31 are significant.
Maybe you can try the suggestions in the warning and see if it helps.
Set GTIFF_SRS_SOURCE configuration option to EPSG to use official parameters (overriding the ones from GeoTIFF keys), or to GEOKEYS to use custom values from GeoTIFF keys and drop the EPSG code.
You can do this via, e.g.:
import os
os.environ['GTIFF_SRS_SOURCE'] = 'GEOKEYS'
or
import os
os.environ['GTIFF_SRS_SOURCE'] = 'EPSG'
I tried both and didn't seem to notice any difference though. My predictions always seem to be aligned correctly.
from raster-vision.
Are you saying that you trained your own model to predict forests, and this was the output? My guess is that the labels were misaligned with your imagery in the training set and the model has learned to reproduce this behavior. I would look at your training images and labels in a tool like QGIS and check the alignment.
from raster-vision.
If your training labels are in a vector format like GeoJSON, you should be able to shift them using the ShiftTransformer which is a type of VectorTransformer
.
from raster-vision.
Yes, I trained the model first, and then used the trained model to predict woodland,the screenshot below is the label and image of the training,the image data format is tif,the label data format is geojson, the coordinate system is wgs84:
from raster-vision.
When I use the trained forest image data model to predict another image data, why does the output geojson result have a position shift?
This is the predict output. The training dataset does not seem to be shifted, but why is the output shifted? I'm confused...
from raster-vision.
Which version of RV are you using and how did you install it? Would you be able to share the model bundle and a sample image where this is happening?
from raster-vision.
@ylfmsn Is the raster prediction output (labels.tif
) also shifted or just the GeoJSON?
from raster-vision.
@ylfmsn Is the raster prediction output (
labels.tif
) also shifted or just the GeoJSON?
labels.tif is also shifted
from raster-vision.
Which version of RV are you using and how did you install it? Would you be able to share the model bundle and a sample image where this is happening?
the raster-vision version is 0.20.2
sample image and model:
image and model.zip
from raster-vision.
@ylfmsn Note that I tested the above inside the RV docker image. It is possible that the difference is due a difference in the GDAL version. The GDAL version (gdalinfo --version
) in the docker image is 3.5.2
. Maybe you can re-try with that version.
Also, the rasterio version is 1.3.2
.
from raster-vision.
@AdeelH Thank you very much for your help, I think I know what the problem is, data offset has bothered me for a long time, I will check the data again, thank you again!
from raster-vision.
@AdeelH I used the coordinate system epsg:2363 of sample.tif for prediction. Why is the output geojson coordinate system wgs84? It seems that no matter what coordinate system I use for sample.tif, the coordinate system of the output geojson is wgs84. How can I set the coordinate system of the output geojson to be the same as that of the input sample.tif?
from raster-vision.
The official GeoJSON standard only supports WGS84. RV complies with that standard. You may be able to use other tools to convert the GeoJSON to other coordinate systems.
Note that there is no similar restriction on the CRS of the GeoTIFF. But the input GeoJSON (for training) is also expected to be WGS84.
from raster-vision.
Related Issues (20)
- Support reading temporal data (i.e. time-series of multiple images of the same scene)
- Can't use a geojson as AOI in a SemanticSegmentationRandomWindowGeoDataset HOT 3
- ARM64 build currently broken HOT 1
- Unable to install RasterVision HOT 3
- Issues with using model bundle for prediction HOT 15
- Cannot import ClassConfig on Kaggle HOT 16
- Cannot save prediction using colors from ClassConfig HOT 4
- Improve unit test coverage of CLI and `Runner`s
- Cannot plot batch with ObjectDetectionVisualizer HOT 4
- Multi-temporal raster source visualizer fails when batch size is 1 HOT 2
- Make it possible to exclude "null" class labels from the computation of metrics HOT 3
- RuntimeError: expected scalar type Long but found Int HOT 10
- Allow user to specify AOI box filtering behavior in sliding window datasets HOT 1
- self._hds cannot be converted to a Python object for pickling HOT 2
- Semantic Segmentation Labels not initializing properly from predictions when extent provided HOT 2
- use my trained modle to prediction ,has wrong happened HOT 2
- RuntimeError: The size of tensor a (82) must match the size of tensor b (64) at non-singleton dimension 3 HOT 4
- Migrate to `pydantic` v2
- MPL notice for use of everett library and LGPL for triangle
- v0.30 release checklist
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 raster-vision.