{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE OverloadedStrings #-}

module RiskWeaver.Cmd.Core where

import Control.Monad
import Data.ByteString qualified as BS
import Data.FileEmbed (embedFile)
import Data.Text qualified as T
import Options.Applicative
import RiskWeaver.Display
import RiskWeaver.Format.Coco
import Data.Text qualified as T
import Data.Text.Encoding qualified as T

data CocoCommand
  = ListImages {CocoCommand -> FilePath
cocoFile :: FilePath}
  | ListCategories {cocoFile :: FilePath}
  | ListAnnotations {cocoFile :: FilePath}
  | ListCocoResult {CocoCommand -> FilePath
cocoResultFile :: FilePath}
  | ShowImage
      { cocoFile :: FilePath,
        CocoCommand -> FilePath
imageFile :: FilePath,
        CocoCommand -> Bool
enableBoundingBox :: Bool
      }
  | ShowDetectionImage
      { cocoFile :: FilePath,
        cocoResultFile :: FilePath,
        imageFile :: FilePath,
        CocoCommand -> Maybe Double
iouThreshold :: Maybe Double,
        CocoCommand -> Maybe Double
scoreThreshold :: Maybe Double
      }
  | Evaluate
      { cocoFile :: FilePath,
        cocoResultFile :: FilePath,
        iouThreshold :: Maybe Double,
        scoreThreshold :: Maybe Double
      }
  | ShowRisk
      { cocoFile :: FilePath,
        cocoResultFile :: FilePath,
        iouThreshold :: Maybe Double,
        scoreThreshold :: Maybe Double
      }
  | ShowRiskWithError
      { cocoFile :: FilePath,
        cocoResultFile :: FilePath,
        iouThreshold :: Maybe Double,
        scoreThreshold :: Maybe Double
      }
  | GenerateRiskWeightedDataset
      { cocoFile :: FilePath,
        cocoResultFile :: FilePath,
        CocoCommand -> FilePath
cocoOutputFile :: FilePath,
        iouThreshold :: Maybe Double,
        scoreThreshold :: Maybe Double
      }
  | BashCompletion
  | GenerateTemplate
  deriving (Int -> CocoCommand -> ShowS
[CocoCommand] -> ShowS
CocoCommand -> FilePath
(Int -> CocoCommand -> ShowS)
-> (CocoCommand -> FilePath)
-> ([CocoCommand] -> ShowS)
-> Show CocoCommand
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CocoCommand -> ShowS
showsPrec :: Int -> CocoCommand -> ShowS
$cshow :: CocoCommand -> FilePath
show :: CocoCommand -> FilePath
$cshowList :: [CocoCommand] -> ShowS
showList :: [CocoCommand] -> ShowS
Show, CocoCommand -> CocoCommand -> Bool
(CocoCommand -> CocoCommand -> Bool)
-> (CocoCommand -> CocoCommand -> Bool) -> Eq CocoCommand
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CocoCommand -> CocoCommand -> Bool
== :: CocoCommand -> CocoCommand -> Bool
$c/= :: CocoCommand -> CocoCommand -> Bool
/= :: CocoCommand -> CocoCommand -> Bool
Eq)

data RiskCommands = RiskCommands
  { RiskCommands -> CocoMap -> Maybe Double -> Maybe Double -> IO ()
showRisk :: CocoMap -> Maybe Double -> Maybe Double -> IO (),
    RiskCommands -> CocoMap -> Maybe Double -> Maybe Double -> IO ()
showRiskWithError :: CocoMap -> Maybe Double -> Maybe Double -> IO (),
    RiskCommands
-> CocoMap -> FilePath -> Maybe Double -> Maybe Double -> IO ()
generateRiskWeightedDataset :: CocoMap -> FilePath -> Maybe Double -> Maybe Double -> IO (),
    RiskCommands
-> CocoMap -> FilePath -> Maybe Double -> Maybe Double -> IO ()
showDetectionImage :: CocoMap -> FilePath -> Maybe Double -> Maybe Double -> IO (),
    RiskCommands -> CocoMap -> Maybe Double -> Maybe Double -> IO ()
evaluate :: CocoMap -> Maybe Double -> Maybe Double -> IO ()
  }

listImages :: Coco -> IO ()
listImages :: Coco -> IO ()
listImages Coco
coco = do
  FilePath -> IO ()
putStrLn FilePath
"-- list images --"
  -- first column is image id
  -- second column is image file name
  -- third column is image width
  -- fourth column is image height
  -- fifth column is image license
  -- sixth column is image date captured
  FilePath -> IO ()
putStrLn FilePath
"id\tfile_name\twidth\theight\tlicense\tdate_captured"
  [CocoImage] -> (CocoImage -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (Coco -> [CocoImage]
cocoImages Coco
coco) ((CocoImage -> IO ()) -> IO ()) -> (CocoImage -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CocoImage {Int
Maybe Int
Maybe Text
Text
ImageId
cocoImageId :: ImageId
cocoImageWidth :: Int
cocoImageHeight :: Int
cocoImageFileName :: Text
cocoImageLicense :: Maybe Int
cocoImageDateCoco :: Maybe Text
cocoImageId :: CocoImage -> ImageId
cocoImageWidth :: CocoImage -> Int
cocoImageHeight :: CocoImage -> Int
cocoImageFileName :: CocoImage -> Text
cocoImageLicense :: CocoImage -> Maybe Int
cocoImageDateCoco :: CocoImage -> Maybe Text
..} -> do
    FilePath -> IO ()
putStrLn (FilePath -> IO ()) -> FilePath -> IO ()
forall a b. (a -> b) -> a -> b
$ Int -> FilePath
forall a. Show a => a -> FilePath
show (ImageId -> Int
unImageId ImageId
cocoImageId) FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
"\t" FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> FilePath
T.unpack Text
cocoImageFileName FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
"\t" FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> FilePath
forall a. Show a => a -> FilePath
show Int
cocoImageWidth FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
"\t" FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> FilePath
forall a. Show a => a -> FilePath
show Int
cocoImageHeight FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
"\t" FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ Maybe Int -> FilePath
forall a. Show a => a -> FilePath
show Maybe Int
cocoImageLicense FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
"\t" FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ Maybe Text -> FilePath
forall a. Show a => a -> FilePath
show Maybe Text
cocoImageDateCoco

listCategories :: Coco -> IO ()
listCategories :: Coco -> IO ()
listCategories Coco
coco = do
  FilePath -> IO ()
putStrLn FilePath
"-- list categories --"
  -- first column is category id
  -- second column is category name
  -- third column is category supercategory
  FilePath -> IO ()
putStrLn FilePath
"id\tname\tsupercategory"
  [CocoCategory] -> (CocoCategory -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (Coco -> [CocoCategory]
cocoCategories Coco
coco) ((CocoCategory -> IO ()) -> IO ())
-> (CocoCategory -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CocoCategory {Text
CategoryId
cocoCategoryId :: CategoryId
cocoCategoryName :: Text
cocoCategorySupercategory :: Text
cocoCategoryId :: CocoCategory -> CategoryId
cocoCategoryName :: CocoCategory -> Text
cocoCategorySupercategory :: CocoCategory -> Text
..} -> do
    FilePath -> IO ()
putStrLn (FilePath -> IO ()) -> FilePath -> IO ()
forall a b. (a -> b) -> a -> b
$ CategoryId -> FilePath
forall a. Show a => a -> FilePath
show CategoryId
cocoCategoryId FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
"\t" FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> FilePath
T.unpack Text
cocoCategoryName FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
"\t" FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> FilePath
T.unpack Text
cocoCategorySupercategory

listAnnotations :: Coco -> IO ()
listAnnotations :: Coco -> IO ()
listAnnotations Coco
coco = do
  FilePath -> IO ()
putStrLn FilePath
"-- list annotations --"
  -- first column is annotation id
  -- second column is annotation image id
  -- third column is annotation category id
  -- fourth column is annotation segmentation
  -- fifth column is annotation area
  -- sixth column is annotation bbox
  -- seventh column is annotation iscrowd
  FilePath -> IO ()
putStrLn FilePath
"id\timage_id\tcategory_id\tsegmentation\tarea\tbbox\tiscrowd"
  [CocoAnnotation] -> (CocoAnnotation -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (Coco -> [CocoAnnotation]
cocoAnnotations Coco
coco) ((CocoAnnotation -> IO ()) -> IO ())
-> (CocoAnnotation -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CocoAnnotation {Double
Int
Maybe Int
Maybe [[Double]]
CoCoBoundingBox
CategoryId
ImageId
cocoAnnotationId :: Int
cocoAnnotationImageId :: ImageId
cocoAnnotationCategory :: CategoryId
cocoAnnotationSegment :: Maybe [[Double]]
cocoAnnotationArea :: Double
cocoAnnotationBbox :: CoCoBoundingBox
cocoAnnotationIsCrowd :: Maybe Int
cocoAnnotationId :: CocoAnnotation -> Int
cocoAnnotationImageId :: CocoAnnotation -> ImageId
cocoAnnotationCategory :: CocoAnnotation -> CategoryId
cocoAnnotationSegment :: CocoAnnotation -> Maybe [[Double]]
cocoAnnotationArea :: CocoAnnotation -> Double
cocoAnnotationBbox :: CocoAnnotation -> CoCoBoundingBox
cocoAnnotationIsCrowd :: CocoAnnotation -> Maybe Int
..} -> do
    FilePath -> IO ()
putStrLn (FilePath -> IO ()) -> FilePath -> IO ()
forall a b. (a -> b) -> a -> b
$ Int -> FilePath
forall a. Show a => a -> FilePath
show Int
cocoAnnotationId FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
"\t" FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ ImageId -> FilePath
forall a. Show a => a -> FilePath
show ImageId
cocoAnnotationImageId FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
"\t" FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ CategoryId -> FilePath
forall a. Show a => a -> FilePath
show CategoryId
cocoAnnotationCategory FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
"\t" FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ Maybe [[Double]] -> FilePath
forall a. Show a => a -> FilePath
show Maybe [[Double]]
cocoAnnotationSegment FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
"\t" FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ Double -> FilePath
forall a. Show a => a -> FilePath
show Double
cocoAnnotationArea FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
"\t" FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ CoCoBoundingBox -> FilePath
forall a. Show a => a -> FilePath
show CoCoBoundingBox
cocoAnnotationBbox FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
"\t" FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ Maybe Int -> FilePath
forall a. Show a => a -> FilePath
show Maybe Int
cocoAnnotationIsCrowd

listCocoResult :: [CocoResult] -> IO ()
listCocoResult :: [CocoResult] -> IO ()
listCocoResult [CocoResult]
cocoResults = do
  FilePath -> IO ()
putStrLn FilePath
"-- list coco result --"
  -- first column is image id
  -- second column is category id
  -- third column is score
  -- fourth column is bbox
  FilePath -> IO ()
putStrLn FilePath
"image_id\tcategory_id\tscore\tbbox"
  [CocoResult] -> (CocoResult -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [CocoResult]
cocoResults ((CocoResult -> IO ()) -> IO ()) -> (CocoResult -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CocoResult
cocoResult -> do
    FilePath -> IO ()
putStrLn (FilePath -> IO ()) -> FilePath -> IO ()
forall a b. (a -> b) -> a -> b
$ ImageId -> FilePath
forall a. Show a => a -> FilePath
show (CocoResult -> ImageId
cocoResultImageId CocoResult
cocoResult) FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
"\t" FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ CategoryId -> FilePath
forall a. Show a => a -> FilePath
show (CocoResult -> CategoryId
cocoResultCategory CocoResult
cocoResult) FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
"\t" FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ Score -> FilePath
forall a. Show a => a -> FilePath
show (CocoResult -> Score
cocoResultScore CocoResult
cocoResult) FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
"\t" FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ CoCoBoundingBox -> FilePath
forall a. Show a => a -> FilePath
show (CocoResult -> CoCoBoundingBox
cocoResultBbox CocoResult
cocoResult)

bashCompletion :: IO ()
bashCompletion :: IO ()
bashCompletion = do
  -- Read from bash_completion.d/risk-weaver-exe and write to stdout
  -- Inline the file content by tepmlate haskell
  let file :: ByteString
file = $(embedFile "bash_completion.d/risk-weaver-exe")
  ByteString -> IO ()
BS.putStr ByteString
file

-- | Generate template codes to define own risk environment from BDD.
generateTemplate :: IO ()
generateTemplate :: IO ()
generateTemplate = do
  -- Read from bash_completion.d/risk-weaver-exe and write to stdout
  -- Inline the file content by tepmlate haskell
  let orgDslFile :: ByteString
orgDslFile = $(embedFile "src/RiskWeaver/DSL/BDD.hs")
      orgCmdFile :: ByteString
orgCmdFile = $(embedFile "src/RiskWeaver/Cmd/BDD.hs")
      mainLine :: ByteString
mainLine = ByteString
"main = baseMain bddCommand\n"
      mergedFile :: ByteString
mergedFile = ByteString
orgDslFile ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
orgCmdFile ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
mainLine
      extraceLangExtFromMergedFile :: ByteString
extraceLangExtFromMergedFile = -- Extract all '{-# LANGUAGE .. #-}' lines
        let langExts :: Text
langExts = [Text] -> Text
T.unlines ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ (Text -> Bool) -> [Text] -> [Text]
forall a. (a -> Bool) -> [a] -> [a]
filter (Text -> Text -> Bool
T.isPrefixOf Text
"{-# LANGUAGE") ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$ Text -> [Text]
T.lines (Text -> [Text]) -> Text -> [Text]
forall a b. (a -> b) -> a -> b
$ ByteString -> Text
T.decodeUtf8 ByteString
mergedFile
         in Text -> ByteString
T.encodeUtf8 Text
langExts
      extractImportLines :: ByteString
extractImportLines = -- Extract all 'import ..' lines
        let importLines :: Text
importLines = [Text] -> Text
T.unlines ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ (Text -> Bool) -> [Text] -> [Text]
forall a. (a -> Bool) -> [a] -> [a]
filter (Text -> Text -> Bool
T.isPrefixOf Text
"import") ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$ Text -> [Text]
T.lines (Text -> [Text]) -> Text -> [Text]
forall a b. (a -> b) -> a -> b
$ ByteString -> Text
T.decodeUtf8 ByteString
mergedFile
         in Text -> ByteString
T.encodeUtf8 Text
importLines
      removeModuleAndLangExtAndImport :: ByteString
removeModuleAndLangExtAndImport = -- Remove module and language extension and import lines
        let removedModule :: Text
removedModule = [Text] -> Text
T.unlines ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ (Text -> Bool) -> [Text] -> [Text]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Text -> Bool) -> Text -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Bool
T.isPrefixOf Text
"module") ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$ Text -> [Text]
T.lines (Text -> [Text]) -> Text -> [Text]
forall a b. (a -> b) -> a -> b
$ ByteString -> Text
T.decodeUtf8 ByteString
mergedFile
            removedLangExt :: Text
removedLangExt = [Text] -> Text
T.unlines ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ (Text -> Bool) -> [Text] -> [Text]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Text -> Bool) -> Text -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Bool
T.isPrefixOf Text
"{-# LANGUAGE") ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$ Text -> [Text]
T.lines Text
removedModule
            removedImport :: Text
removedImport = [Text] -> Text
T.unlines ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ (Text -> Bool) -> [Text] -> [Text]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Text -> Bool) -> Text -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Bool
T.isPrefixOf Text
"import") ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$ Text -> [Text]
T.lines Text
removedLangExt
         in Text -> ByteString
T.encodeUtf8 Text
removedImport
      output :: ByteString
output = -- Concat all of them(extraceLangExtFromMergedFile, extractImportLines, removeModuleAndLangExtAndImport)
        ByteString
extraceLangExtFromMergedFile ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"\n" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
extractImportLines ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"\n" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
removeModuleAndLangExtAndImport
  ByteString -> IO ()
BS.putStr ByteString
output


opts :: Parser CocoCommand
opts :: Parser CocoCommand
opts =
  Mod CommandFields CocoCommand -> Parser CocoCommand
forall a. Mod CommandFields a -> Parser a
subparser
    ( FilePath -> ParserInfo CocoCommand -> Mod CommandFields CocoCommand
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"list-images" (Parser CocoCommand -> InfoMod CocoCommand -> ParserInfo CocoCommand
forall a. Parser a -> InfoMod a -> ParserInfo a
info (FilePath -> CocoCommand
ListImages (FilePath -> CocoCommand) -> Parser FilePath -> Parser CocoCommand
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM FilePath -> Mod ArgumentFields FilePath -> Parser FilePath
forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ReadM FilePath
forall s. IsString s => ReadM s
str (FilePath -> Mod ArgumentFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"FILE")) (FilePath -> InfoMod CocoCommand
forall a. FilePath -> InfoMod a
progDesc FilePath
"list all images of coco file"))
        Mod CommandFields CocoCommand
-> Mod CommandFields CocoCommand -> Mod CommandFields CocoCommand
forall a. Semigroup a => a -> a -> a
<> FilePath -> ParserInfo CocoCommand -> Mod CommandFields CocoCommand
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"list-categories" (Parser CocoCommand -> InfoMod CocoCommand -> ParserInfo CocoCommand
forall a. Parser a -> InfoMod a -> ParserInfo a
info (FilePath -> CocoCommand
ListCategories (FilePath -> CocoCommand) -> Parser FilePath -> Parser CocoCommand
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM FilePath -> Mod ArgumentFields FilePath -> Parser FilePath
forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ReadM FilePath
forall s. IsString s => ReadM s
str (FilePath -> Mod ArgumentFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"FILE")) (FilePath -> InfoMod CocoCommand
forall a. FilePath -> InfoMod a
progDesc FilePath
"list all categories of coco file"))
        Mod CommandFields CocoCommand
-> Mod CommandFields CocoCommand -> Mod CommandFields CocoCommand
forall a. Semigroup a => a -> a -> a
<> FilePath -> ParserInfo CocoCommand -> Mod CommandFields CocoCommand
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"list-annotations" (Parser CocoCommand -> InfoMod CocoCommand -> ParserInfo CocoCommand
forall a. Parser a -> InfoMod a -> ParserInfo a
info (FilePath -> CocoCommand
ListAnnotations (FilePath -> CocoCommand) -> Parser FilePath -> Parser CocoCommand
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM FilePath -> Mod ArgumentFields FilePath -> Parser FilePath
forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ReadM FilePath
forall s. IsString s => ReadM s
str (FilePath -> Mod ArgumentFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"FILE")) (FilePath -> InfoMod CocoCommand
forall a. FilePath -> InfoMod a
progDesc FilePath
"list all annotations of coco file"))
        Mod CommandFields CocoCommand
-> Mod CommandFields CocoCommand -> Mod CommandFields CocoCommand
forall a. Semigroup a => a -> a -> a
<> FilePath -> ParserInfo CocoCommand -> Mod CommandFields CocoCommand
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"list-coco-result" (Parser CocoCommand -> InfoMod CocoCommand -> ParserInfo CocoCommand
forall a. Parser a -> InfoMod a -> ParserInfo a
info (FilePath -> CocoCommand
ListCocoResult (FilePath -> CocoCommand) -> Parser FilePath -> Parser CocoCommand
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM FilePath -> Mod ArgumentFields FilePath -> Parser FilePath
forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ReadM FilePath
forall s. IsString s => ReadM s
str (FilePath -> Mod ArgumentFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"FILE")) (FilePath -> InfoMod CocoCommand
forall a. FilePath -> InfoMod a
progDesc FilePath
"list all coco result"))
        Mod CommandFields CocoCommand
-> Mod CommandFields CocoCommand -> Mod CommandFields CocoCommand
forall a. Semigroup a => a -> a -> a
<> FilePath -> ParserInfo CocoCommand -> Mod CommandFields CocoCommand
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"show-image" (Parser CocoCommand -> InfoMod CocoCommand -> ParserInfo CocoCommand
forall a. Parser a -> InfoMod a -> ParserInfo a
info (FilePath -> FilePath -> Bool -> CocoCommand
ShowImage (FilePath -> FilePath -> Bool -> CocoCommand)
-> Parser FilePath -> Parser (FilePath -> Bool -> CocoCommand)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM FilePath -> Mod ArgumentFields FilePath -> Parser FilePath
forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ReadM FilePath
forall s. IsString s => ReadM s
str (FilePath -> Mod ArgumentFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"FILE") Parser (FilePath -> Bool -> CocoCommand)
-> Parser FilePath -> Parser (Bool -> CocoCommand)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReadM FilePath -> Mod ArgumentFields FilePath -> Parser FilePath
forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ReadM FilePath
forall s. IsString s => ReadM s
str (FilePath -> Mod ArgumentFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"IMAGE_FILE") Parser (Bool -> CocoCommand) -> Parser Bool -> Parser CocoCommand
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mod FlagFields Bool -> Parser Bool
switch (FilePath -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"enable-bounding-box" Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<> Char -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'b' Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod FlagFields Bool
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"enable bounding box")) (FilePath -> InfoMod CocoCommand
forall a. FilePath -> InfoMod a
progDesc FilePath
"show image by sixel"))
        Mod CommandFields CocoCommand
-> Mod CommandFields CocoCommand -> Mod CommandFields CocoCommand
forall a. Semigroup a => a -> a -> a
<> FilePath -> ParserInfo CocoCommand -> Mod CommandFields CocoCommand
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"show-detection-image" (Parser CocoCommand -> InfoMod CocoCommand -> ParserInfo CocoCommand
forall a. Parser a -> InfoMod a -> ParserInfo a
info (FilePath
-> FilePath
-> FilePath
-> Maybe Double
-> Maybe Double
-> CocoCommand
ShowDetectionImage (FilePath
 -> FilePath
 -> FilePath
 -> Maybe Double
 -> Maybe Double
 -> CocoCommand)
-> Parser FilePath
-> Parser
     (FilePath
      -> FilePath -> Maybe Double -> Maybe Double -> CocoCommand)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM FilePath -> Mod ArgumentFields FilePath -> Parser FilePath
forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ReadM FilePath
forall s. IsString s => ReadM s
str (FilePath -> Mod ArgumentFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"FILE") Parser
  (FilePath
   -> FilePath -> Maybe Double -> Maybe Double -> CocoCommand)
-> Parser FilePath
-> Parser (FilePath -> Maybe Double -> Maybe Double -> CocoCommand)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReadM FilePath -> Mod ArgumentFields FilePath -> Parser FilePath
forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ReadM FilePath
forall s. IsString s => ReadM s
str (FilePath -> Mod ArgumentFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"RESULT_FILE") Parser (FilePath -> Maybe Double -> Maybe Double -> CocoCommand)
-> Parser FilePath
-> Parser (Maybe Double -> Maybe Double -> CocoCommand)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReadM FilePath -> Mod ArgumentFields FilePath -> Parser FilePath
forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ReadM FilePath
forall s. IsString s => ReadM s
str (FilePath -> Mod ArgumentFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"IMAGE_FILE") Parser (Maybe Double -> Maybe Double -> CocoCommand)
-> Parser (Maybe Double) -> Parser (Maybe Double -> CocoCommand)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Double -> Parser (Maybe Double)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (ReadM Double -> Mod OptionFields Double -> Parser Double
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM Double
forall a. Read a => ReadM a
auto (FilePath -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"iou-threshold" Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<> Char -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'i' Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields Double
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"iou threshold")) Parser (Maybe Double -> CocoCommand)
-> Parser (Maybe Double) -> Parser CocoCommand
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Double -> Parser (Maybe Double)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (ReadM Double -> Mod OptionFields Double -> Parser Double
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM Double
forall a. Read a => ReadM a
auto (FilePath -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"score-threshold" Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<> Char -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
's' Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields Double
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"score threshold"))) (FilePath -> InfoMod CocoCommand
forall a. FilePath -> InfoMod a
progDesc FilePath
"show detection image by sixel"))
        Mod CommandFields CocoCommand
-> Mod CommandFields CocoCommand -> Mod CommandFields CocoCommand
forall a. Semigroup a => a -> a -> a
<> FilePath -> ParserInfo CocoCommand -> Mod CommandFields CocoCommand
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"evaluate" (Parser CocoCommand -> InfoMod CocoCommand -> ParserInfo CocoCommand
forall a. Parser a -> InfoMod a -> ParserInfo a
info (FilePath -> FilePath -> Maybe Double -> Maybe Double -> CocoCommand
Evaluate (FilePath
 -> FilePath -> Maybe Double -> Maybe Double -> CocoCommand)
-> Parser FilePath
-> Parser (FilePath -> Maybe Double -> Maybe Double -> CocoCommand)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM FilePath -> Mod ArgumentFields FilePath -> Parser FilePath
forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ReadM FilePath
forall s. IsString s => ReadM s
str (FilePath -> Mod ArgumentFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"FILE") Parser (FilePath -> Maybe Double -> Maybe Double -> CocoCommand)
-> Parser FilePath
-> Parser (Maybe Double -> Maybe Double -> CocoCommand)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReadM FilePath -> Mod ArgumentFields FilePath -> Parser FilePath
forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ReadM FilePath
forall s. IsString s => ReadM s
str (FilePath -> Mod ArgumentFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"RESULT_FILE") Parser (Maybe Double -> Maybe Double -> CocoCommand)
-> Parser (Maybe Double) -> Parser (Maybe Double -> CocoCommand)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Double -> Parser (Maybe Double)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (ReadM Double -> Mod OptionFields Double -> Parser Double
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM Double
forall a. Read a => ReadM a
auto (FilePath -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"iou-threshold" Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<> Char -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'i' Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields Double
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"iou threshold")) Parser (Maybe Double -> CocoCommand)
-> Parser (Maybe Double) -> Parser CocoCommand
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Double -> Parser (Maybe Double)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (ReadM Double -> Mod OptionFields Double -> Parser Double
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM Double
forall a. Read a => ReadM a
auto (FilePath -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"score-threshold" Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<> Char -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
's' Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields Double
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"score threshold"))) (FilePath -> InfoMod CocoCommand
forall a. FilePath -> InfoMod a
progDesc FilePath
"evaluate coco result"))
        Mod CommandFields CocoCommand
-> Mod CommandFields CocoCommand -> Mod CommandFields CocoCommand
forall a. Semigroup a => a -> a -> a
<> FilePath -> ParserInfo CocoCommand -> Mod CommandFields CocoCommand
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"show-risk" (Parser CocoCommand -> InfoMod CocoCommand -> ParserInfo CocoCommand
forall a. Parser a -> InfoMod a -> ParserInfo a
info (FilePath -> FilePath -> Maybe Double -> Maybe Double -> CocoCommand
ShowRisk (FilePath
 -> FilePath -> Maybe Double -> Maybe Double -> CocoCommand)
-> Parser FilePath
-> Parser (FilePath -> Maybe Double -> Maybe Double -> CocoCommand)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM FilePath -> Mod ArgumentFields FilePath -> Parser FilePath
forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ReadM FilePath
forall s. IsString s => ReadM s
str (FilePath -> Mod ArgumentFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"FILE") Parser (FilePath -> Maybe Double -> Maybe Double -> CocoCommand)
-> Parser FilePath
-> Parser (Maybe Double -> Maybe Double -> CocoCommand)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReadM FilePath -> Mod ArgumentFields FilePath -> Parser FilePath
forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ReadM FilePath
forall s. IsString s => ReadM s
str (FilePath -> Mod ArgumentFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"RESULT_FILE") Parser (Maybe Double -> Maybe Double -> CocoCommand)
-> Parser (Maybe Double) -> Parser (Maybe Double -> CocoCommand)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Double -> Parser (Maybe Double)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (ReadM Double -> Mod OptionFields Double -> Parser Double
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM Double
forall a. Read a => ReadM a
auto (FilePath -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"iou-threshold" Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<> Char -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'i' Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields Double
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"iou threshold")) Parser (Maybe Double -> CocoCommand)
-> Parser (Maybe Double) -> Parser CocoCommand
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Double -> Parser (Maybe Double)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (ReadM Double -> Mod OptionFields Double -> Parser Double
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM Double
forall a. Read a => ReadM a
auto (FilePath -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"score-threshold" Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<> Char -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
's' Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields Double
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"score threshold"))) (FilePath -> InfoMod CocoCommand
forall a. FilePath -> InfoMod a
progDesc FilePath
"show risk"))
        Mod CommandFields CocoCommand
-> Mod CommandFields CocoCommand -> Mod CommandFields CocoCommand
forall a. Semigroup a => a -> a -> a
<> FilePath -> ParserInfo CocoCommand -> Mod CommandFields CocoCommand
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"show-risk-with-error" (Parser CocoCommand -> InfoMod CocoCommand -> ParserInfo CocoCommand
forall a. Parser a -> InfoMod a -> ParserInfo a
info (FilePath -> FilePath -> Maybe Double -> Maybe Double -> CocoCommand
ShowRiskWithError (FilePath
 -> FilePath -> Maybe Double -> Maybe Double -> CocoCommand)
-> Parser FilePath
-> Parser (FilePath -> Maybe Double -> Maybe Double -> CocoCommand)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM FilePath -> Mod ArgumentFields FilePath -> Parser FilePath
forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ReadM FilePath
forall s. IsString s => ReadM s
str (FilePath -> Mod ArgumentFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"FILE") Parser (FilePath -> Maybe Double -> Maybe Double -> CocoCommand)
-> Parser FilePath
-> Parser (Maybe Double -> Maybe Double -> CocoCommand)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReadM FilePath -> Mod ArgumentFields FilePath -> Parser FilePath
forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ReadM FilePath
forall s. IsString s => ReadM s
str (FilePath -> Mod ArgumentFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"RESULT_FILE") Parser (Maybe Double -> Maybe Double -> CocoCommand)
-> Parser (Maybe Double) -> Parser (Maybe Double -> CocoCommand)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Double -> Parser (Maybe Double)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (ReadM Double -> Mod OptionFields Double -> Parser Double
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM Double
forall a. Read a => ReadM a
auto (FilePath -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"iou-threshold" Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<> Char -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'i' Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields Double
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"iou threshold")) Parser (Maybe Double -> CocoCommand)
-> Parser (Maybe Double) -> Parser CocoCommand
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Double -> Parser (Maybe Double)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (ReadM Double -> Mod OptionFields Double -> Parser Double
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM Double
forall a. Read a => ReadM a
auto (FilePath -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"score-threshold" Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<> Char -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
's' Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields Double
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"score threshold"))) (FilePath -> InfoMod CocoCommand
forall a. FilePath -> InfoMod a
progDesc FilePath
"show risk with error"))
        Mod CommandFields CocoCommand
-> Mod CommandFields CocoCommand -> Mod CommandFields CocoCommand
forall a. Semigroup a => a -> a -> a
<> FilePath -> ParserInfo CocoCommand -> Mod CommandFields CocoCommand
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"generate-risk-weighted-dataset" (Parser CocoCommand -> InfoMod CocoCommand -> ParserInfo CocoCommand
forall a. Parser a -> InfoMod a -> ParserInfo a
info (FilePath
-> FilePath
-> FilePath
-> Maybe Double
-> Maybe Double
-> CocoCommand
GenerateRiskWeightedDataset (FilePath
 -> FilePath
 -> FilePath
 -> Maybe Double
 -> Maybe Double
 -> CocoCommand)
-> Parser FilePath
-> Parser
     (FilePath
      -> FilePath -> Maybe Double -> Maybe Double -> CocoCommand)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM FilePath -> Mod ArgumentFields FilePath -> Parser FilePath
forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ReadM FilePath
forall s. IsString s => ReadM s
str (FilePath -> Mod ArgumentFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"FILE") Parser
  (FilePath
   -> FilePath -> Maybe Double -> Maybe Double -> CocoCommand)
-> Parser FilePath
-> Parser (FilePath -> Maybe Double -> Maybe Double -> CocoCommand)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReadM FilePath -> Mod ArgumentFields FilePath -> Parser FilePath
forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ReadM FilePath
forall s. IsString s => ReadM s
str (FilePath -> Mod ArgumentFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"RESULT_FILE") Parser (FilePath -> Maybe Double -> Maybe Double -> CocoCommand)
-> Parser FilePath
-> Parser (Maybe Double -> Maybe Double -> CocoCommand)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReadM FilePath -> Mod ArgumentFields FilePath -> Parser FilePath
forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ReadM FilePath
forall s. IsString s => ReadM s
str (FilePath -> Mod ArgumentFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"OUTPUT_FILE") Parser (Maybe Double -> Maybe Double -> CocoCommand)
-> Parser (Maybe Double) -> Parser (Maybe Double -> CocoCommand)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Double -> Parser (Maybe Double)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (ReadM Double -> Mod OptionFields Double -> Parser Double
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM Double
forall a. Read a => ReadM a
auto (FilePath -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"iou-threshold" Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<> Char -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'i' Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields Double
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"iou threshold")) Parser (Maybe Double -> CocoCommand)
-> Parser (Maybe Double) -> Parser CocoCommand
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Double -> Parser (Maybe Double)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (ReadM Double -> Mod OptionFields Double -> Parser Double
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM Double
forall a. Read a => ReadM a
auto (FilePath -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"score-threshold" Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<> Char -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
's' Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields Double
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"score threshold"))) (FilePath -> InfoMod CocoCommand
forall a. FilePath -> InfoMod a
progDesc FilePath
"generate risk weighted dataset"))
        Mod CommandFields CocoCommand
-> Mod CommandFields CocoCommand -> Mod CommandFields CocoCommand
forall a. Semigroup a => a -> a -> a
<> FilePath -> ParserInfo CocoCommand -> Mod CommandFields CocoCommand
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"bash-completion" (Parser CocoCommand -> InfoMod CocoCommand -> ParserInfo CocoCommand
forall a. Parser a -> InfoMod a -> ParserInfo a
info (CocoCommand -> Parser CocoCommand
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CocoCommand
BashCompletion) (FilePath -> InfoMod CocoCommand
forall a. FilePath -> InfoMod a
progDesc FilePath
"bash completion"))
        Mod CommandFields CocoCommand
-> Mod CommandFields CocoCommand -> Mod CommandFields CocoCommand
forall a. Semigroup a => a -> a -> a
<> FilePath -> ParserInfo CocoCommand -> Mod CommandFields CocoCommand
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"generate-template" (Parser CocoCommand -> InfoMod CocoCommand -> ParserInfo CocoCommand
forall a. Parser a -> InfoMod a -> ParserInfo a
info (CocoCommand -> Parser CocoCommand
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CocoCommand
GenerateTemplate) (FilePath -> InfoMod CocoCommand
forall a. FilePath -> InfoMod a
progDesc FilePath
"generate template"))
    )

baseMain :: RiskCommands -> IO ()
baseMain :: RiskCommands -> IO ()
baseMain RiskCommands
hook = do
  CocoCommand
parsedCommand <- ParserPrefs -> ParserInfo CocoCommand -> IO CocoCommand
forall a. ParserPrefs -> ParserInfo a -> IO a
customExecParser (PrefsMod -> ParserPrefs
prefs PrefsMod
showHelpOnEmpty) (Parser CocoCommand -> InfoMod CocoCommand -> ParserInfo CocoCommand
forall a. Parser a -> InfoMod a -> ParserInfo a
info (Parser (CocoCommand -> CocoCommand)
forall a. Parser (a -> a)
helper Parser (CocoCommand -> CocoCommand)
-> Parser CocoCommand -> Parser CocoCommand
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser CocoCommand
opts) (InfoMod CocoCommand
forall a. InfoMod a
fullDesc InfoMod CocoCommand -> InfoMod CocoCommand -> InfoMod CocoCommand
forall a. Semigroup a => a -> a -> a
<> FilePath -> InfoMod CocoCommand
forall a. FilePath -> InfoMod a
progDesc FilePath
"coco command line tool"))

  case CocoCommand
parsedCommand of
    CocoCommand
BashCompletion -> IO ()
bashCompletion
    ListImages FilePath
cocoFile -> do
      Coco
coco <- FilePath -> IO Coco
readCoco FilePath
cocoFile
      Coco -> IO ()
listImages Coco
coco
    ListCategories FilePath
cocoFile -> do
      Coco
coco <- FilePath -> IO Coco
readCoco FilePath
cocoFile
      Coco -> IO ()
listCategories Coco
coco
    ListAnnotations FilePath
cocoFile -> do
      Coco
coco <- FilePath -> IO Coco
readCoco FilePath
cocoFile
      Coco -> IO ()
listAnnotations Coco
coco
    ListCocoResult FilePath
cocoResultFile -> do
      [CocoResult]
cocoResult <- FilePath -> IO [CocoResult]
readCocoResult FilePath
cocoResultFile
      [CocoResult] -> IO ()
listCocoResult [CocoResult]
cocoResult
    ShowImage FilePath
cocoFile FilePath
imageFile Bool
enableBoundingBox -> do
      Coco
coco <- FilePath -> IO Coco
readCoco FilePath
cocoFile
      Coco -> FilePath -> FilePath -> Bool -> IO ()
showImage Coco
coco FilePath
cocoFile FilePath
imageFile Bool
enableBoundingBox
    ShowDetectionImage FilePath
cocoFile FilePath
cocoResultFile FilePath
imageFile Maybe Double
iouThreshold Maybe Double
scoreThreshold -> do
      CocoMap
cocoMap <- FilePath -> FilePath -> IO CocoMap
readCocoMap FilePath
cocoFile FilePath
cocoResultFile
      RiskCommands
hook.showDetectionImage CocoMap
cocoMap FilePath
imageFile Maybe Double
iouThreshold Maybe Double
scoreThreshold
    Evaluate FilePath
cocoFile FilePath
cocoResultFile Maybe Double
iouThreshold Maybe Double
scoreThreshold -> do
      CocoMap
cocoMap <- FilePath -> FilePath -> IO CocoMap
readCocoMap FilePath
cocoFile FilePath
cocoResultFile
      RiskCommands
hook.evaluate CocoMap
cocoMap Maybe Double
iouThreshold Maybe Double
scoreThreshold
    ShowRisk FilePath
cocoFile FilePath
cocoResultFile Maybe Double
iouThreshold Maybe Double
scoreThreshold -> do
      CocoMap
cocoMap <- FilePath -> FilePath -> IO CocoMap
readCocoMap FilePath
cocoFile FilePath
cocoResultFile
      RiskCommands
hook.showRisk CocoMap
cocoMap Maybe Double
iouThreshold Maybe Double
scoreThreshold
    ShowRiskWithError FilePath
cocoFile FilePath
cocoResultFile Maybe Double
iouThreshold Maybe Double
scoreThreshold -> do
      CocoMap
cocoMap <- FilePath -> FilePath -> IO CocoMap
readCocoMap FilePath
cocoFile FilePath
cocoResultFile
      RiskCommands
hook.showRiskWithError CocoMap
cocoMap Maybe Double
iouThreshold Maybe Double
scoreThreshold
    GenerateRiskWeightedDataset FilePath
cocoFile FilePath
cocoResultFile FilePath
cocoOutputFile Maybe Double
iouThreshold Maybe Double
scoreThreshold -> do
      CocoMap
cocoMap <- FilePath -> FilePath -> IO CocoMap
readCocoMap FilePath
cocoFile FilePath
cocoResultFile
      RiskCommands
hook.generateRiskWeightedDataset CocoMap
cocoMap FilePath
cocoOutputFile Maybe Double
iouThreshold Maybe Double
scoreThreshold
    CocoCommand
GenerateTemplate -> IO ()
generateTemplate