Esempio n. 1
0
func main() {

	config := *(et.NewDefaultConfiguration())

	numCbfsNodes := os.Args[1]

	if numCbfsNodes == "" {
		logg.LogFatal("Must pass in the number of cbfs nodes as 1st arg")
		return
	}

	numCbfsNodesInt, err := strconv.ParseInt(numCbfsNodes, 10, 64)
	if err != nil {
		logg.LogFatal("Could not parse %v into int", numCbfsNodes)
		return
	}

	config.NumCbfsClusterNodes = int(numCbfsNodesInt)

	if err = et.EnvironmentSanityCheck(config); err != nil {
		logg.LogFatal("Failed environment sanity check: %v", err)
		return
	}

}
func (s StrokeWidthTransformer) preprocess(ocrRequest *OcrRequest) error {

	// write bytes to a temp file

	tmpFileNameInput, err := createTempFileName()
	tmpFileNameInput = fmt.Sprintf("%s.png", tmpFileNameInput)
	if err != nil {
		return err
	}
	defer os.Remove(tmpFileNameInput)

	tmpFileNameOutput, err := createTempFileName()
	tmpFileNameOutput = fmt.Sprintf("%s.png", tmpFileNameOutput)
	if err != nil {
		return err
	}
	defer os.Remove(tmpFileNameOutput)

	err = saveBytesToFileName(ocrRequest.ImgBytes, tmpFileNameInput)
	if err != nil {
		return err
	}

	// run DecodeText binary on it (if not in path, print warning and do nothing)
	darkOnLightSetting := s.extractDarkOnLightParam(*ocrRequest)
	logg.LogTo(
		"PREPROCESSOR_WORKER",
		"DetectText on %s -> %s with %s",
		tmpFileNameInput,
		tmpFileNameOutput,
		darkOnLightSetting,
	)
	out, err := exec.Command(
		"DetectText",
		tmpFileNameInput,
		tmpFileNameOutput,
		darkOnLightSetting,
	).CombinedOutput()
	if err != nil {
		logg.LogFatal("Error running command: %s.  out: %s", err, out)
	}
	logg.LogTo("PREPROCESSOR_WORKER", "output: %v", string(out))

	// read bytes from output file into ocrRequest.ImgBytes
	resultBytes, err := ioutil.ReadFile(tmpFileNameOutput)
	if err != nil {
		return err
	}

	ocrRequest.ImgBytes = resultBytes

	return nil

}
Esempio n. 3
0
func main() {

	config := *(et.NewDefaultConfiguration()) // TODO: get these vals from cmd line args

	if err := et.EnvironmentSanityCheck(config); err != nil {
		logg.LogFatal("Failed environment sanity check: %v", err)
		return
	}

	worker := et.NewNsqWorker(config)
	go worker.HandleEvents()

	select {} // block forever

}
func (w *PreprocessorRpcWorker) strokeWidthTransform(ocrRequest *OcrRequest) error {

	// write bytes to a temp file

	tmpFileNameInput, err := createTempFileName()
	if err != nil {
		return err
	}
	defer os.Remove(tmpFileNameInput)

	tmpFileNameOutput, err := createTempFileName()
	if err != nil {
		return err
	}
	defer os.Remove(tmpFileNameOutput)

	err = saveBytesToFileName(ocrRequest.ImgBytes, tmpFileNameInput)
	if err != nil {
		return err
	}

	// run DecodeText binary on it (if not in path, print warning and do nothing)
	darkOnLightSetting := "1" // todo: this should be passed as a param.
	out, err := exec.Command(
		"DetectText",
		tmpFileNameInput,
		tmpFileNameOutput,
		darkOnLightSetting,
	).CombinedOutput()
	if err != nil {
		logg.LogFatal("Error running command: %s.  out: %s", err, out)
	}
	logg.LogTo("PREPROCESSOR_WORKER", "output: %v", string(out))

	// read bytes from output file into ocrRequest.ImgBytes
	resultBytes, err := ioutil.ReadFile(tmpFileNameOutput)
	if err != nil {
		return err
	}

	ocrRequest.ImgBytes = resultBytes

	return nil

}
Esempio n. 5
0
// How to run this code:
// $ cd examples
// $ go build -v && go run run_examples.go run_stochastic_hill_climber.go run_topology_mutating_trainer.go
func main() {

	go http.ListenAndServe(":8080", nil)

	// RunStochasticHillClimber()
	// success := MultiRunTopologyMutatingTrainer()

	/*
		success := RunTopologyMutatingTrainer()
		if !success {
			logg.LogPanic("Failed to run example")
		}
	*/

	success := RunPopulationTrainerLoop(150)
	if !success {
		logg.LogFatal("Failed to run population trainer")
	}

}
Esempio n. 6
0
func main() {

	// TODO: customize listen port (defaults to 8080)

	usage := `ElasticThought REST API server.

Usage:
  elastic-thought [--sync-gw-url=<sgu>] [--blob-store-url=<bsu>]

Options:
  -h --help     Show this screen.
  --sync-gw-url=<sgu>  Sync Gateway DB URL [default: http://localhost:4985/elastic-thought].
  --blob-store-url=<bsu>  Blob store URL [default: file:///tmp].`

	parsedDocOptArgs, _ := docopt.Parse(usage, nil, true, "ElasticThought alpha", false)
	fmt.Println(parsedDocOptArgs)

	config := *(et.NewDefaultConfiguration())

	config, err := config.Merge(parsedDocOptArgs)
	if err != nil {
		logg.LogFatal("Error processing cmd line args: %v", err)
		return
	}

	if err := et.EnvironmentSanityCheck(config); err != nil {
		logg.LogFatal("Failed environment sanity check: %v", err)
		return
	}

	var jobScheduler et.JobScheduler

	switch config.QueueType {
	case et.Nsq:
		jobScheduler = et.NewNsqJobScheduler(config)
	case et.Goroutine:
		jobScheduler = et.NewInProcessJobScheduler(config)
	default:
		logg.LogFatal("Unexpected queue type: %v", config.QueueType)
	}

	context := &et.EndpointContext{
		Configuration: config,
	}

	changesListener, err := et.NewChangesListener(config, jobScheduler)
	if err != nil {
		logg.LogPanic("Error creating changes listener: %v", err)
	}
	go changesListener.FollowChangesFeed()

	ginEngine := gin.Default()

	// all requests wrapped in database connection middleware
	ginEngine.Use(et.DbConnector(config.DbUrl))

	// endpoint to create a new user (db auth not required)
	ginEngine.POST("/users", context.CreateUserEndpoint)

	// TODO: bundle in static assets from ../../example directory into the
	// binary using gobin-data and then allow them to be served up
	// via the /example REST endpoint.
	// ginEngine.Static("/example", "../../example")  <-- uncomment for quick hack rel path

	// all endpoints in the authorized group require Basic Auth credentials
	// which is enforced by the DbAuthRequired middleware.
	authorized := ginEngine.Group("/")
	authorized.Use(et.DbAuthRequired())
	{
		authorized.POST("/datafiles", context.CreateDataFileEndpoint)
		authorized.POST("/datasets", context.CreateDataSetsEndpoint)
		authorized.POST("/solvers", context.CreateSolverEndpoint)
		authorized.POST("/training-jobs", context.CreateTrainingJob)
		authorized.POST("/classifiers", context.CreateClassifierEndpoint)
		authorized.POST("/classifiers/:classifier-id/classify", context.CreateClassificationJobEndpoint)
	}

	// Listen and serve on 0.0.0.0:8080
	ginEngine.Run(":8080")

}