示例#1
0
def run():
    ########################################################################
    # Register Prediction Start
    ########################################################################
    aicrowd_helpers.execution_start()

    ########################################################################
    # Load Tests Meta Data file
    #       and iterate over all its rows
    #
    #       Each Row contains the following information :
    #
    #       - hashed_id  : a unique id for each test image
    #       - filename   : filename of the image
    #       - country    : Country where this image was taken
    #       - continent  : Continent where this image was taken
    ########################################################################

    OUTPUT_LINES = []
    HEADER = ['hashed_id'] + VALID_SNAKE_SPECIES
    OUTPUT_LINES.append(",".join(HEADER))

    tests_df = pd.read_csv(AICROWD_TEST_METADATA_PATH)
    for _idx, row in tests_df.iterrows():
        image_id = row["hashed_id"]
        country = row["country"]
        continent = row["continent"]
        filename = row["filename"]
        filepath = os.path.join(AICROWD_TEST_IMAGES_PATH, filename)

        predictions = get_random_prediction(image_id)
        PREDICTION_LINE = [image_id] + [str(x) for x in predictions.tolist()]
        OUTPUT_LINES.append(",".join(PREDICTION_LINE))

        ########################################################################
        # Register Prediction
        #
        # Note, this prediction register is not a requirement. It is used to
        # provide you feedback of how far are you in the overall evaluation.
        # In the absence of it, the evaluation will still work, but you
        # will see progress of the evaluation as 0 until it is complete
        #
        # Here you simply announce that you completed processing a set of
        # image_ids
        ########################################################################
        aicrowd_helpers.execution_progress({
            "image_ids": [image_id]  ### NOTE : This is an array of image_ids 
        })

    # Write output
    fp = open(AICROWD_PREDICTIONS_OUTPUT_PATH, "w")
    fp.write("\n".join(OUTPUT_LINES))
    fp.close()
    ########################################################################
    # Register Prediction Complete
    ########################################################################
    aicrowd_helpers.execution_success(
        {"predictions_output_path": AICROWD_PREDICTIONS_OUTPUT_PATH})
示例#2
0
def run():
	########################################################################
	# Register Prediction Start
	########################################################################
	aicrowd_helpers.execution_start()

	########################################################################
	# Gather Input and Output paths from environment variables
	########################################################################
	test_images_path, predictions_output_path = gather_input_output_path()

	########################################################################
	# Generate Predictions
	########################################################################
	cfg = get_cfg()
	cfg.merge_from_file(model_zoo.get_config_file("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml"))
	cfg.MODEL.WEIGHTS = model_path
	cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = threshold   # set the testing threshold for this model
	cfg.MODEL.ROI_HEADS.NUM_CLASSES = 273
	#cfg.MODEL.DEVICE = "cpu"
	predictor = DefaultPredictor(cfg)
	results = []
	del cfg
	for i in os.listdir(test_images_path):
		img_path =test_images_path + "/" +str(i)
		im = cv2.imread(img_path)
		outputs = predictor(im)
		instances = outputs["instances"].to(cpu_device)
		fname = int(i.split('.')[0])
		result = instances_to_coco_json(instances,fname)
		if(len(result)!=0):
			for ele in result:
				matchId = ele['category_id']
				ele['category_id'] = reverse_id_mapping[str(matchId)]
				results.append(ele)    
			aicrowd_helpers.execution_progress({
				"image_ids" : [fname]
			})





	# Write output
	fp = open(predictions_output_path, "w")
	fp.write(json.dumps(results))
	fp.close()
	########################################################################
	# Register Prediction Complete
	########################################################################
	aicrowd_helpers.execution_success({
	"predictions_output_path" : predictions_output_path
	})
def run():
    ########################################################################
    # Register Prediction Start
    ########################################################################
    aicrowd_helpers.execution_start()

    ########################################################################
    # Gather Input and Output paths from environment variables
    ########################################################################
    test_images_path, predictions_output_path = gather_input_output_path()

    ########################################################################
    # Gather Image IDS
    ########################################################################
    image_ids = gather_image_ids(test_images_path)

    ########################################################################
    # Generate Predictions
    ########################################################################
    predictions = []
    print("Number of images found:", len(image_ids))
    for image_id in image_ids:
        number_of_annotations = np.random.randint(0, MAX_NUMBER_OF_ANNOTATIONS)
        for _idx in range(number_of_annotations):
            print(image_id)
            _annotation = single_annotation(image_id)
            predictions.append(_annotation)
        ########################################################################
        # Register Prediction
        #
        # Note, this prediction register is not a requirement. It is used to
        # provide you feedback of how far are you in the overall evaluation.
        # In the absence of it, the evaluation will still work, but you
        # will see progress of the evaluation as 0 until it is complete
        #
        # Here you simply announce that you completed processing a set of
        # image-ids
        ########################################################################
        aicrowd_helpers.execution_progress({"image_ids": [image_id]})

    # Write output
    fp = open(predictions_output_path, "w")
    fp.write(json.dumps(predictions))
    fp.close()
    ########################################################################
    # Register Prediction Complete
    ########################################################################
    aicrowd_helpers.execution_success(
        {"predictions_output_path": predictions_output_path})
def run():
    ########################################################################
    # Register Prediction Start
    ########################################################################
    aicrowd_helpers.execution_start()

    ########################################################################
    # Gather Input and Output paths from environment variables
    ########################################################################
    test_images_path, predictions_output_path = gather_input_output_path()

    ########################################################################
    # Gather Image Names
    ########################################################################
    image_names = gather_image_names(test_images_path)

    ########################################################################
    # Do your magic here to train the model
    ########################################################################
    classes = get_snake_classes()

    def softmax(x):
        """Compute softmax values for each sets of scores in x."""
        e_x = np.exp(x - np.max(x))
        return e_x / e_x.sum(axis=0)

    ########################################################################
    # Generate Predictions
    ########################################################################
    LINES = []
    LINES.append(','.join(['filename'] + classes))
    predictions = []
    for image_name in image_names:
        probs = softmax(np.random.rand(45))
        probs = list(map(str, probs))
        LINES.append(",".join([image_name] + probs))

        ########################################################################
        # Register Prediction
        #
        # Note, this prediction register is not a requirement. It is used to
        # provide you feedback of how far are you in the overall evaluation.
        # In the absence of it, the evaluation will still work, but you
        # will see progress of the evaluation as 0 until it is complete
        #
        # Here you simply announce that you completed processing a set of
        # image_names
        ########################################################################
        aicrowd_helpers.execution_progress({
            "image_names" : [image_name]
        })


    # Write output
    fp = open(predictions_output_path, "w")
    fp.write("\n".join(LINES))
    fp.close()
    ########################################################################
    # Register Prediction Complete
    ########################################################################
    aicrowd_helpers.execution_success({
        "predictions_output_path" : predictions_output_path
    })
示例#5
0
def run():
    ########################################################################
    # Register Prediction Start
    ########################################################################
    aicrowd_helpers.execution_start()


    ########################################################################
    # Load Tests Meta Data file
    #       and iterate over all its rows
    #
    #       Each Row contains the following information : 
    #
    #       - `index` : Unique ID of each record
    #       - `intclinicaltrialid` : description to be added
    #       - `intdesignkeywordid` : description to be added
    #       - `strdesignkeyword` : description to be added
    #       - .... and so on 
    ########################################################################    

    OUTPUT_LINES = []
    HEADER = ['index'] + VALID_CLASSES
    OUTPUT_LINES.append(",".join(HEADER))

    tests_df = pd.read_csv(AICROWD_TEST_DATA_PATH, index_col=0)

    for index_id, row in tqdm.tqdm(tests_df.iterrows()):
        index_id = str(index_id)
        intclinicaltrialid = row['intclinicaltrialid']
        intdesignkeywordid = row['intdesignkeywordid']
        ##
        ## ... and so on 
        ## TODO : Provide example re

        predictions = get_random_prediction(index_id)
        PREDICTION_LINE = [index_id] + [str(x) for x in predictions.tolist()]
        OUTPUT_LINES.append(",".join(PREDICTION_LINE))
        
        ########################################################################
        # Register Prediction
        #
        # Note, this prediction register is not a requirement. It is used to
        # provide you feedback of how far are you in the overall evaluation.
        # In the absence of it, the evaluation will still work, but you
        # will see progress of the evaluation as 0 until it is complete
        #
        # Here you simply announce that you completed processing a set of
        # index_ids
        ########################################################################
        aicrowd_helpers.execution_progress({
            "index_ids" : [index_id] ### NOTE : This is an array of index_ids 
        })


    # Write output
    fp = open(AICROWD_PREDICTIONS_OUTPUT_PATH, "w")
    fp.write("\n".join(OUTPUT_LINES))
    fp.close()
    ########################################################################
    # Register Prediction Complete
    ########################################################################
    aicrowd_helpers.execution_success({
        "predictions_output_path" : AICROWD_PREDICTIONS_OUTPUT_PATH
    })
示例#6
0
        probs = list(map(str, probs))
        LINES.append(",".join([image_name] + probs))

        ########################################################################
        # Register Prediction
        #
        # Note, this prediction register is not a requirement. It is used to
        # provide you feedback of how far are you in the overall evaluation.
        # In the absence of it, the evaluation will still work, but you
        # will see progress of the evaluation as 0 until it is complete
        #
        # Here you simply announce that you completed processing a set of
        # image_names
        ########################################################################
        aicrowd_helpers.execution_progress({
            "image_names" : [image_name]
        })


    # Write output
    fp = open(predictions_output_path, "w")
    fp.write("\n".join(LINES))
    fp.close()
    ########################################################################
    # Register Prediction Complete
    ########################################################################
    aicrowd_helpers.execution_success({
        "predictions_output_path" : predictions_output_path
    })