| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
import argparse |
| 16 |
import os |
| 17 |
import math |
| 18 |
import jiplib as jl |
| 19 |
|
| 20 |
parser=argparse.ArgumentParser() |
| 21 |
parser.add_argument("-input","--input",help="Path of the input raster dataset",dest="input",required=True,type=str) |
| 22 |
parser.add_argument("-vector","--vector",help="Path of the sample vector dataset with labels",dest="vector",required=True,type=str) |
| 23 |
parser.add_argument("-model","--model",help="Path of the model output filename used for training",dest="model",required=True,type=str) |
| 24 |
parser.add_argument("-output","--output",help="Path of the classification output raster dataset",dest="output",required=True,type=str) |
| 25 |
parser.add_argument("-classifier","--classifier",help="classifier (svm, ann)",dest="classifier",required=False,type=str,default="svm") |
| 26 |
args = parser.parse_args() |
| 27 |
|
| 28 |
try: |
| 29 |
print("createJim") |
| 30 |
jim=jl.createJim(args.input) |
| 31 |
print("createVector") |
| 32 |
sample=jl.createVector(); |
| 33 |
print("open vector",args.vector) |
| 34 |
sample.open(args.vector) |
| 35 |
print("extractOgr") |
| 36 |
training=jim.extractOgr(sample,{'output':'training','oformat':'Memory','copy':'label'}) |
| 37 |
if args.classifier == 'svm': |
| 38 |
|
| 39 |
print("training") |
| 40 |
training.train({'method':'svm','label':'label','model':args.model}) |
| 41 |
print("classification") |
| 42 |
jim_classify=jim.classify({'method':'svm','model':args.model}) |
| 43 |
jim_classify.write({'filename':args.output}) |
| 44 |
jim_classify.close() |
| 45 |
else: |
| 46 |
|
| 47 |
training.train({'method':'ann','label':'label','model':args.model}) |
| 48 |
jim_classify=jim.classify({'method':'ann','model':args.model}) |
| 49 |
jim_classify.write({'filename':args.output}) |
| 50 |
jim_classify.close() |
| 51 |
sample.close() |
| 52 |
training.close() |
| 53 |
jim.close() |
| 54 |
print("Success: classify") |
| 55 |
except: |
| 56 |
print("Failed: classify") |