Giter VIP home page Giter VIP logo

Comments (13)

AdeelH avatar AdeelH commented on June 12, 2024 1

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:
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:
image

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.

lewfish avatar lewfish commented on June 12, 2024

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.

lewfish avatar lewfish commented on June 12, 2024

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.

ylfmsn avatar ylfmsn commented on June 12, 2024

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:
image
image

from raster-vision.

ylfmsn avatar ylfmsn commented on June 12, 2024

When I use the trained forest image data model to predict another image data, why does the output geojson result have a position shift?

image image

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.

lewfish avatar lewfish commented on June 12, 2024

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.

AdeelH avatar AdeelH commented on June 12, 2024

@ylfmsn Is the raster prediction output (labels.tif) also shifted or just the GeoJSON?

from raster-vision.

ylfmsn avatar ylfmsn commented on June 12, 2024

@ylfmsn Is the raster prediction output (labels.tif) also shifted or just the GeoJSON?

labels.tif is also shifted

from raster-vision.

ylfmsn avatar ylfmsn commented on June 12, 2024

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.

AdeelH avatar AdeelH commented on June 12, 2024

@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.

ylfmsn avatar ylfmsn commented on June 12, 2024

@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.

ylfmsn avatar ylfmsn commented on June 12, 2024

@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.

AdeelH avatar AdeelH commented on June 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.