randomforestforremotesensing's People
Forkers
benitezrcamilo essaaya huipengxi mmfink yangxhcaf jonasviehweger hartantoprayudha zjinwen77 jalaska xyt556 fkanzy at175 robinkwik viniciuspg sonthuybacha leonarduart-usp yijiecaomingrandomforestforremotesensing's Issues
Functional Training Collection
Hi,
You may recall me from my e-mails. I tried to write sth to collect training values more efficiently. If you may consider integrating, I'd be happy to contribute.
For the case of adding the number of samples, I first wrote a function:
# LOAD LIBRARIES
require(sf)
library(raster)
library(rgdal)
library(tidyverse)
library(tools)
library(data.table)
library(furrr)
options(warn=-1)
set.seed(2012)
# COLLECTION FUNCTION
collectTrain <- function(classNums = c(11, 12, 13),
classSampNums = c(0, 0, 0),
inImageName = "___.tif",
shapefile = "___.shp",
attName = 'id',
nd = 0) {
# Read vector file
vec <- st_read(shapefile)
vec <- st_zm(vec)# To prevent possible errors
# Load the image then flag all no-data values(nd) so they are not processed
satImage <- brick(inImageName)
NAvalue(satImage) <- nd
# Create vector of unique land cover attribute values
polygons <- vec[which(vec[[attName]] %in% classNums),]
points <- st_sf(st_sample(polygons, classSampNums))
# Getting Point Attributes
pointTable <- st_join(points, polygons, join = st_intersects)
# Preparing Columns
coords <- st_coordinates(pointTable)
predictors <- within(raster::extract(satImage, pointTable, df=TRUE), rm('ID'))
attributes <- within(as.data.table(pointTable), rm('geometry'))
# Combine Columns
trainvals <- cbind(attributes, coords, predictors)
return(trainvals)
}
Then I define my variables as:
# SET VARIABLES
args <- list(classNums = c(11, 12, 13),
classSampNums = c(1000, 1000, 1000),
inImageName = "20190703-04_plamsc_sub.tif",
shapefile = "Karacabey_Dataset_FULL.shp",
attName = 'id',
nd = 0)
outputCSV <- "TrainSet_200320.csv"
Using furrr
package, I collect training values as:
# COLLECTION
cat("Create training data to train model\n")
list_train <- furrr::future_pmap(args, collectTrain)
trainvals <- dplyr::bind_rows(list_train)
I simply use your idea and put it into a function to do operations as list-based. This way should be more efficient since we got rid of for loops. This approach can be extended to other parts.
I'll try to improve the code above. I am planning to collect all related things for Random Forest Image Classification in a package later. If you have a similar idea, I'm happy to contribute.
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.