feat: HSAP platform v2 — modular navigation, quality review, audit log, world model simulation
Major changes: - New frontend (platform/web/): Vite + React 18 + TypeScript + Tailwind - 4-module navigation: 数据送标 / 模型管理 / 车队管理 / 系统管理 - Data catalog with charts (DMS/ADAS/Lane 3-tab view) - Quality review workflow (标注质检): Good/Fine/Bad scoring with auto-advance - Audit enhancements: batch operations, rejection categories, Feishu notifications - Operation audit log (操作日志) - World model simulation studio (仿真工坊) - Dataset version management with snapshots and diff - ADAS 7-class dataset integration (138K images organized + compressed) - User management with Feishu integration and pagination - CRUD/search/filter on all pages, card layout redesign - PIL-optimized image overlay rendering - Auto-snapshot on build, in_review workflow stage - Removed embedded algorithm code (now in workspace)
This commit is contained in:
79
algorithms/lane_ufld/code.embedded.bak/UFLD/evaluation/culane/CMakeLists.txt
Executable file
79
algorithms/lane_ufld/code.embedded.bak/UFLD/evaluation/culane/CMakeLists.txt
Executable file
@@ -0,0 +1,79 @@
|
||||
# Thanks for the contribution of zchrissirhcz imzhuo@foxmail.com
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
|
||||
project(culane_evaluator)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
add_definitions(
|
||||
-DCPU_ONLY
|
||||
)
|
||||
|
||||
set(SRC_LST
|
||||
${CMAKE_SOURCE_DIR}/src/counter.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/evaluate.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/lane_compare.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/spline.cpp
|
||||
)
|
||||
|
||||
set(HDR_LST
|
||||
${CMAKE_SOURCE_DIR}/include/counter.hpp
|
||||
${CMAKE_SOURCE_DIR}/include/hungarianGraph.hpp
|
||||
${CMAKE_SOURCE_DIR}/include/lane_compare.hpp
|
||||
${CMAKE_SOURCE_DIR}/include/spline.hpp
|
||||
)
|
||||
|
||||
if (CMAKE_SYSTEM_NAME MATCHES "Windows")
|
||||
list(APPEND SRC_LST ${CMAKE_SOURCE_DIR}/getopt/getopt.c)
|
||||
list(APPEND HDR_LST ${CMAKE_SOURCE_DIR}/getopt/getopt.h)
|
||||
endif()
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
${SRC_LST}
|
||||
${HDR_LST}
|
||||
)
|
||||
|
||||
set(dep_libs "")
|
||||
|
||||
#--- OpenCV
|
||||
# You may switch different version of OpenCV like this:
|
||||
# set(OpenCV_DIR "/usr/local/opencv-4.3.0" CACHE PATH "")
|
||||
find_package(OpenCV REQUIRED
|
||||
COMPONENTS core highgui imgproc imgcodecs
|
||||
)
|
||||
if(NOT OpenCV_FOUND) # if not OpenCV 4.x/3.x, then imgcodecs are not found
|
||||
find_package(OpenCV REQUIRED COMPONENTS core highgui imgproc)
|
||||
endif()
|
||||
|
||||
list(APPEND dep_libs
|
||||
PUBLIC ${OpenCV_LIBS}
|
||||
)
|
||||
|
||||
#--- OpenMP
|
||||
find_package(OpenMP)
|
||||
if(NOT TARGET OpenMP::OpenMP_CXX AND (OpenMP_CXX_FOUND OR OPENMP_FOUND))
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE ${OpenMP_CXX_FLAGS})
|
||||
endif()
|
||||
|
||||
if(OpenMP_CXX_FOUND OR OPENMP_FOUND)
|
||||
message(STATUS "Building with OpenMP")
|
||||
if(OpenMP_CXX_FOUND)
|
||||
list(APPEND dep_libs PUBLIC OpenMP::OpenMP_CXX)
|
||||
else()
|
||||
list(APPEND dep_libs PRIVATE "${OpenMP_CXX_FLAGS}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(dep_incs ${CMAKE_SOURCE_DIR}/include)
|
||||
if (CMAKE_SYSTEM_NAME MATCHES "Windows")
|
||||
list(APPEND dep_incs "${CMAKE_SOURCE_DIR}/getopt")
|
||||
endif()
|
||||
|
||||
# --- target config with include dirs / libs
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
${dep_libs}
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PUBLIC ${dep_incs}
|
||||
)
|
||||
50
algorithms/lane_ufld/code.embedded.bak/UFLD/evaluation/culane/Makefile
Executable file
50
algorithms/lane_ufld/code.embedded.bak/UFLD/evaluation/culane/Makefile
Executable file
@@ -0,0 +1,50 @@
|
||||
PROJECT_NAME:= evaluate
|
||||
|
||||
# config ----------------------------------
|
||||
|
||||
INCLUDE_DIRS := include
|
||||
LIBRARY_DIRS := lib
|
||||
|
||||
# You may switch different versions of opencv like this:
|
||||
# export PKG_CONFIG_PATH=/usr/local/opencv-4.1.1/lib/pkgconfig:$PKG_CONFIG_PATH
|
||||
# then use `pkg-config opencv4 --cflags --libs` since `opencv4.pc` is found
|
||||
|
||||
COMMON_FLAGS := -DCPU_ONLY
|
||||
CXXFLAGS := -std=c++11 -fopenmp #`pkg-config --cflags opencv`
|
||||
LDFLAGS := -fopenmp -Wl,-rpath,./lib #`pkg-config --libs opencv`
|
||||
|
||||
BUILD_DIR := build
|
||||
|
||||
# make rules -------------------------------
|
||||
CXX ?= g++
|
||||
BUILD_DIR ?= ./build
|
||||
|
||||
LIBRARIES += opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs
|
||||
|
||||
CXXFLAGS += $(COMMON_FLAGS) $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir))
|
||||
LDFLAGS += $(COMMON_FLAGS) $(foreach includedir,$(LIBRARY_DIRS),-L$(includedir)) $(foreach library,$(LIBRARIES),-l$(library))
|
||||
SRC_DIRS += $(shell find * -type d -exec bash -c "find {} -maxdepth 1 \( -name '*.cpp' -o -name '*.proto' \) | grep -q ." \; -print)
|
||||
CXX_SRCS += $(shell find src/ -name "*.cpp")
|
||||
CXX_TARGETS:=$(patsubst %.cpp, $(BUILD_DIR)/%.o, $(CXX_SRCS))
|
||||
ALL_BUILD_DIRS := $(sort $(BUILD_DIR) $(addprefix $(BUILD_DIR)/, $(SRC_DIRS)))
|
||||
|
||||
.PHONY: all
|
||||
all: $(PROJECT_NAME)
|
||||
|
||||
.PHONY: $(ALL_BUILD_DIRS)
|
||||
$(ALL_BUILD_DIRS):
|
||||
@mkdir -p $@
|
||||
|
||||
$(BUILD_DIR)/%.o: %.cpp | $(ALL_BUILD_DIRS)
|
||||
@echo "CXX" $<
|
||||
@$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||
|
||||
$(PROJECT_NAME): $(CXX_TARGETS)
|
||||
@echo "CXX/LD" $@
|
||||
@$(CXX) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
@rm -rf $(CXX_TARGETS)
|
||||
@rm -rf $(PROJECT_NAME)
|
||||
@rm -rf $(BUILD_DIR)
|
||||
23
algorithms/lane_ufld/code.embedded.bak/UFLD/evaluation/culane/calTotal.m
Executable file
23
algorithms/lane_ufld/code.embedded.bak/UFLD/evaluation/culane/calTotal.m
Executable file
@@ -0,0 +1,23 @@
|
||||
%% Calculate overall Fmeasure from each scenarios
|
||||
clc; clear; close all;
|
||||
|
||||
allFile = 'output/vgg_SCNN_DULR_w9_iou0.5.txt';
|
||||
|
||||
all = textread(allFile,'%s');
|
||||
TP = 0;
|
||||
FP = 0;
|
||||
FN = 0;
|
||||
|
||||
for i=1:9
|
||||
tpline = (i-1)*14+4;
|
||||
tp = str2double(all(tpline));
|
||||
fp = str2double(all(tpline+2));
|
||||
fn = str2double(all(tpline+4));
|
||||
TP = TP + tp;
|
||||
FP = FP + fp;
|
||||
FN = FN + fn;
|
||||
end
|
||||
|
||||
P = TP/(TP + FP)
|
||||
R = TP/(TP + FN)
|
||||
F = 2*P*R/(P + R)*100
|
||||
201
algorithms/lane_ufld/code.embedded.bak/UFLD/evaluation/culane/getopt/LICENSE.md
Executable file
201
algorithms/lane_ufld/code.embedded.bak/UFLD/evaluation/culane/getopt/LICENSE.md
Executable file
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@@ -0,0 +1,51 @@
|
||||
/* *****************************************************************
|
||||
*
|
||||
* Copyright 2016 Microsoft
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
#include "getopt.h"
|
||||
#include <windows.h>
|
||||
|
||||
char* optarg = NULL;
|
||||
int optind = 1;
|
||||
|
||||
int getopt(int argc, char *const argv[], const char *optstring)
|
||||
{
|
||||
if ((optind >= argc) || (argv[optind][0] != '-') || (argv[optind][0] == 0))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int opt = argv[optind][1];
|
||||
const char *p = strchr(optstring, opt);
|
||||
|
||||
if (p == NULL)
|
||||
{
|
||||
return '?';
|
||||
}
|
||||
if (p[1] == ':')
|
||||
{
|
||||
optind++;
|
||||
if (optind >= argc)
|
||||
{
|
||||
return '?';
|
||||
}
|
||||
optarg = argv[optind];
|
||||
optind++;
|
||||
}
|
||||
return opt;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/* *****************************************************************
|
||||
*
|
||||
* Copyright 2016 Microsoft
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
#ifndef GETOPT_H__
|
||||
#define GETOPT_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
|
||||
int getopt(int argc, char *const argv[], const char *optstring);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,3 @@
|
||||
For windows build, `getopt.c` and `getopt.h` are required.
|
||||
|
||||
They are taken from the [iotivity](https://github.com/iotivity/iotivity) open source project, under Apache LICENSE 2.0.
|
||||
@@ -0,0 +1,47 @@
|
||||
#ifndef COUNTER_HPP
|
||||
#define COUNTER_HPP
|
||||
|
||||
#include "lane_compare.hpp"
|
||||
#include "hungarianGraph.hpp"
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
// before coming to use functions of this class, the lanes should resize to im_width and im_height using resize_lane() in lane_compare.hpp
|
||||
class Counter
|
||||
{
|
||||
public:
|
||||
Counter(int _im_width, int _im_height, double _iou_threshold=0.4, int _lane_width=10):tp(0),fp(0),fn(0){
|
||||
im_width = _im_width;
|
||||
im_height = _im_height;
|
||||
sim_threshold = _iou_threshold;
|
||||
lane_compare = new LaneCompare(_im_width, _im_height, _lane_width, LaneCompare::IOU);
|
||||
};
|
||||
double get_precision(void);
|
||||
double get_recall(void);
|
||||
long getTP(void);
|
||||
long getFP(void);
|
||||
long getFN(void);
|
||||
void setTP(long);
|
||||
void setFP(long);
|
||||
void setFN(long);
|
||||
// direct add tp, fp, tn and fn
|
||||
// first match with hungarian
|
||||
tuple<vector<int>, long, long, long, long> count_im_pair(const vector<vector<Point2f> > &anno_lanes, const vector<vector<Point2f> > &detect_lanes);
|
||||
void makeMatch(const vector<vector<double> > &similarity, vector<int> &match1, vector<int> &match2);
|
||||
|
||||
private:
|
||||
double sim_threshold;
|
||||
int im_width;
|
||||
int im_height;
|
||||
long tp;
|
||||
long fp;
|
||||
long fn;
|
||||
LaneCompare *lane_compare;
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,71 @@
|
||||
#ifndef HUNGARIAN_GRAPH_HPP
|
||||
#define HUNGARIAN_GRAPH_HPP
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
struct pipartiteGraph {
|
||||
vector<vector<double> > mat;
|
||||
vector<bool> leftUsed, rightUsed;
|
||||
vector<double> leftWeight, rightWeight;
|
||||
vector<int>rightMatch, leftMatch;
|
||||
int leftNum, rightNum;
|
||||
bool matchDfs(int u) {
|
||||
leftUsed[u] = true;
|
||||
for (int v = 0; v < rightNum; v++) {
|
||||
if (!rightUsed[v] && fabs(leftWeight[u] + rightWeight[v] - mat[u][v]) < 1e-2) {
|
||||
rightUsed[v] = true;
|
||||
if (rightMatch[v] == -1 || matchDfs(rightMatch[v])) {
|
||||
rightMatch[v] = u;
|
||||
leftMatch[u] = v;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void resize(int leftNum, int rightNum) {
|
||||
this->leftNum = leftNum;
|
||||
this->rightNum = rightNum;
|
||||
leftMatch.resize(leftNum);
|
||||
rightMatch.resize(rightNum);
|
||||
leftUsed.resize(leftNum);
|
||||
rightUsed.resize(rightNum);
|
||||
leftWeight.resize(leftNum);
|
||||
rightWeight.resize(rightNum);
|
||||
mat.resize(leftNum);
|
||||
for (int i = 0; i < leftNum; i++) mat[i].resize(rightNum);
|
||||
}
|
||||
void match() {
|
||||
for (int i = 0; i < leftNum; i++) leftMatch[i] = -1;
|
||||
for (int i = 0; i < rightNum; i++) rightMatch[i] = -1;
|
||||
for (int i = 0; i < rightNum; i++) rightWeight[i] = 0;
|
||||
for (int i = 0; i < leftNum; i++) {
|
||||
leftWeight[i] = -1e5;
|
||||
for (int j = 0; j < rightNum; j++) {
|
||||
if (leftWeight[i] < mat[i][j]) leftWeight[i] = mat[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
for (int u = 0; u < leftNum; u++) {
|
||||
while (1) {
|
||||
for (int i = 0; i < leftNum; i++) leftUsed[i] = false;
|
||||
for (int i = 0; i < rightNum; i++) rightUsed[i] = false;
|
||||
if (matchDfs(u)) break;
|
||||
double d = 1e10;
|
||||
for (int i = 0; i < leftNum; i++) {
|
||||
if (leftUsed[i] ) {
|
||||
for (int j = 0; j < rightNum; j++) {
|
||||
if (!rightUsed[j]) d = min(d, leftWeight[i] + rightWeight[j] - mat[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (d == 1e10) return ;
|
||||
for (int i = 0; i < leftNum; i++) if (leftUsed[i]) leftWeight[i] -= d;
|
||||
for (int i = 0; i < rightNum; i++) if (rightUsed[i]) rightWeight[i] += d;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // HUNGARIAN_GRAPH_HPP
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef LANE_COMPARE_HPP
|
||||
#define LANE_COMPARE_HPP
|
||||
|
||||
#include "spline.hpp"
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
class LaneCompare{
|
||||
public:
|
||||
enum CompareMode{
|
||||
IOU,
|
||||
Caltech
|
||||
};
|
||||
|
||||
LaneCompare(int _im_width, int _im_height, int _lane_width = 10, CompareMode _compare_mode = IOU){
|
||||
im_width = _im_width;
|
||||
im_height = _im_height;
|
||||
compare_mode = _compare_mode;
|
||||
lane_width = _lane_width;
|
||||
}
|
||||
|
||||
double get_lane_similarity(const vector<Point2f> &lane1, const vector<Point2f> &lane2);
|
||||
void resize_lane(vector<Point2f> &curr_lane, int curr_width, int curr_height);
|
||||
private:
|
||||
CompareMode compare_mode;
|
||||
int im_width;
|
||||
int im_height;
|
||||
int lane_width;
|
||||
Spline splineSolver;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef SPLINE_HPP
|
||||
#define SPLINE_HPP
|
||||
#include <vector>
|
||||
#include <cstdio>
|
||||
#include <math.h>
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
struct Func {
|
||||
double a_x;
|
||||
double b_x;
|
||||
double c_x;
|
||||
double d_x;
|
||||
double a_y;
|
||||
double b_y;
|
||||
double c_y;
|
||||
double d_y;
|
||||
double h;
|
||||
};
|
||||
class Spline {
|
||||
public:
|
||||
vector<Point2f> splineInterpTimes(const vector<Point2f> &tmp_line, int times);
|
||||
vector<Point2f> splineInterpStep(vector<Point2f> tmp_line, double step);
|
||||
vector<Func> cal_fun(const vector<Point2f> &point_v);
|
||||
};
|
||||
#endif
|
||||
37
algorithms/lane_ufld/code.embedded.bak/UFLD/evaluation/culane/run-full.sh
Executable file
37
algorithms/lane_ufld/code.embedded.bak/UFLD/evaluation/culane/run-full.sh
Executable file
@@ -0,0 +1,37 @@
|
||||
root=../../
|
||||
data_dir=${root}data/CULane/
|
||||
exp=vgg_SCNN_DULR_w9
|
||||
detect_dir=${root}tools/prob2lines/output/${exp}/
|
||||
w_lane=30;
|
||||
iou=0.5; # Set iou to 0.3 or 0.5
|
||||
im_w=1640
|
||||
im_h=590
|
||||
frame=1
|
||||
list0=${data_dir}list/test_split/test0_normal.txt
|
||||
list1=${data_dir}list/test_split/test1_crowd.txt
|
||||
list2=${data_dir}list/test_split/test2_hlight.txt
|
||||
list3=${data_dir}list/test_split/test3_shadow.txt
|
||||
list4=${data_dir}list/test_split/test4_noline.txt
|
||||
list5=${data_dir}list/test_split/test5_arrow.txt
|
||||
list6=${data_dir}list/test_split/test6_curve.txt
|
||||
list7=${data_dir}list/test_split/test7_cross.txt
|
||||
list8=${data_dir}list/test_split/test8_night.txt
|
||||
out0=./output/out0_normal.txt
|
||||
out1=./output/out1_crowd.txt
|
||||
out2=./output/out2_hlight.txt
|
||||
out3=./output/out3_shadow.txt
|
||||
out4=./output/out4_noline.txt
|
||||
out5=./output/out5_arrow.txt
|
||||
out6=./output/out6_curve.txt
|
||||
out7=./output/out7_cross.txt
|
||||
out8=./output/out8_night.txt
|
||||
./evaluate -a $data_dir -d $detect_dir -i $data_dir -l $list0 -w $w_lane -t $iou -c $im_w -r $im_h -f $frame -o $out0
|
||||
./evaluate -a $data_dir -d $detect_dir -i $data_dir -l $list1 -w $w_lane -t $iou -c $im_w -r $im_h -f $frame -o $out1
|
||||
./evaluate -a $data_dir -d $detect_dir -i $data_dir -l $list2 -w $w_lane -t $iou -c $im_w -r $im_h -f $frame -o $out2
|
||||
./evaluate -a $data_dir -d $detect_dir -i $data_dir -l $list3 -w $w_lane -t $iou -c $im_w -r $im_h -f $frame -o $out3
|
||||
./evaluate -a $data_dir -d $detect_dir -i $data_dir -l $list4 -w $w_lane -t $iou -c $im_w -r $im_h -f $frame -o $out4
|
||||
./evaluate -a $data_dir -d $detect_dir -i $data_dir -l $list5 -w $w_lane -t $iou -c $im_w -r $im_h -f $frame -o $out5
|
||||
./evaluate -a $data_dir -d $detect_dir -i $data_dir -l $list6 -w $w_lane -t $iou -c $im_w -r $im_h -f $frame -o $out6
|
||||
./evaluate -a $data_dir -d $detect_dir -i $data_dir -l $list7 -w $w_lane -t $iou -c $im_w -r $im_h -f $frame -o $out7
|
||||
./evaluate -a $data_dir -d $detect_dir -i $data_dir -l $list8 -w $w_lane -t $iou -c $im_w -r $im_h -f $frame -o $out8
|
||||
cat ./output/out*.txt>./output/${exp}_iou${iou}_split.txt
|
||||
12
algorithms/lane_ufld/code.embedded.bak/UFLD/evaluation/culane/run-lite.sh
Executable file
12
algorithms/lane_ufld/code.embedded.bak/UFLD/evaluation/culane/run-lite.sh
Executable file
@@ -0,0 +1,12 @@
|
||||
root=../../
|
||||
data_dir=${root}data/CULane/
|
||||
exp=vgg_SCNN_DULR_w9
|
||||
detect_dir=${root}tools/prob2lines/output/${exp}/
|
||||
w_lane=30;
|
||||
iou=0.5; # Set iou to 0.3 or 0.5
|
||||
im_w=1640
|
||||
im_h=590
|
||||
frame=1
|
||||
list=${data_dir}list/test.txt
|
||||
out=./output/${exp}_iou${iou}.txt
|
||||
./evaluate -a $data_dir -d $detect_dir -i $data_dir -l $list -w $w_lane -t $iou -c $im_w -r $im_h -f $frame -o $out
|
||||
134
algorithms/lane_ufld/code.embedded.bak/UFLD/evaluation/culane/src/counter.cpp
Executable file
134
algorithms/lane_ufld/code.embedded.bak/UFLD/evaluation/culane/src/counter.cpp
Executable file
@@ -0,0 +1,134 @@
|
||||
/*************************************************************************
|
||||
> File Name: counter.cpp
|
||||
> Author: Xingang Pan, Jun Li
|
||||
> Mail: px117@ie.cuhk.edu.hk
|
||||
> Created Time: Thu Jul 14 20:23:08 2016
|
||||
************************************************************************/
|
||||
|
||||
#include "counter.hpp"
|
||||
|
||||
double Counter::get_precision(void)
|
||||
{
|
||||
cerr<<"tp: "<<tp<<" fp: "<<fp<<" fn: "<<fn<<endl;
|
||||
if(tp+fp == 0)
|
||||
{
|
||||
cerr<<"no positive detection"<<endl;
|
||||
return -1;
|
||||
}
|
||||
return tp/double(tp + fp);
|
||||
}
|
||||
|
||||
double Counter::get_recall(void)
|
||||
{
|
||||
if(tp+fn == 0)
|
||||
{
|
||||
cerr<<"no ground truth positive"<<endl;
|
||||
return -1;
|
||||
}
|
||||
return tp/double(tp + fn);
|
||||
}
|
||||
|
||||
long Counter::getTP(void)
|
||||
{
|
||||
return tp;
|
||||
}
|
||||
|
||||
long Counter::getFP(void)
|
||||
{
|
||||
return fp;
|
||||
}
|
||||
|
||||
long Counter::getFN(void)
|
||||
{
|
||||
return fn;
|
||||
}
|
||||
|
||||
void Counter::setTP(long value)
|
||||
{
|
||||
tp = value;
|
||||
}
|
||||
|
||||
void Counter::setFP(long value)
|
||||
{
|
||||
fp = value;
|
||||
}
|
||||
|
||||
void Counter::setFN(long value)
|
||||
{
|
||||
fn = value;
|
||||
}
|
||||
|
||||
tuple<vector<int>, long, long, long, long> Counter::count_im_pair(const vector<vector<Point2f> > &anno_lanes, const vector<vector<Point2f> > &detect_lanes)
|
||||
{
|
||||
vector<int> anno_match(anno_lanes.size(), -1);
|
||||
vector<int> detect_match;
|
||||
if(anno_lanes.empty())
|
||||
{
|
||||
return make_tuple(anno_match, 0, detect_lanes.size(), 0, 0);
|
||||
}
|
||||
|
||||
if(detect_lanes.empty())
|
||||
{
|
||||
return make_tuple(anno_match, 0, 0, 0, anno_lanes.size());
|
||||
}
|
||||
// hungarian match first
|
||||
|
||||
// first calc similarity matrix
|
||||
vector<vector<double> > similarity(anno_lanes.size(), vector<double>(detect_lanes.size(), 0));
|
||||
for(int i=0; i<anno_lanes.size(); i++)
|
||||
{
|
||||
const vector<Point2f> &curr_anno_lane = anno_lanes[i];
|
||||
for(int j=0; j<detect_lanes.size(); j++)
|
||||
{
|
||||
const vector<Point2f> &curr_detect_lane = detect_lanes[j];
|
||||
similarity[i][j] = lane_compare->get_lane_similarity(curr_anno_lane, curr_detect_lane);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
makeMatch(similarity, anno_match, detect_match);
|
||||
|
||||
|
||||
int curr_tp = 0;
|
||||
// count and add
|
||||
for(int i=0; i<anno_lanes.size(); i++)
|
||||
{
|
||||
if(anno_match[i]>=0 && similarity[i][anno_match[i]] > sim_threshold)
|
||||
{
|
||||
curr_tp++;
|
||||
}
|
||||
else
|
||||
{
|
||||
anno_match[i] = -1;
|
||||
}
|
||||
}
|
||||
int curr_fn = anno_lanes.size() - curr_tp;
|
||||
int curr_fp = detect_lanes.size() - curr_tp;
|
||||
return make_tuple(anno_match, curr_tp, curr_fp, 0, curr_fn);
|
||||
}
|
||||
|
||||
|
||||
void Counter::makeMatch(const vector<vector<double> > &similarity, vector<int> &match1, vector<int> &match2) {
|
||||
int m = similarity.size();
|
||||
int n = similarity[0].size();
|
||||
pipartiteGraph gra;
|
||||
bool have_exchange = false;
|
||||
if (m > n) {
|
||||
have_exchange = true;
|
||||
swap(m, n);
|
||||
}
|
||||
gra.resize(m, n);
|
||||
for (int i = 0; i < gra.leftNum; i++) {
|
||||
for (int j = 0; j < gra.rightNum; j++) {
|
||||
if(have_exchange)
|
||||
gra.mat[i][j] = similarity[j][i];
|
||||
else
|
||||
gra.mat[i][j] = similarity[i][j];
|
||||
}
|
||||
}
|
||||
gra.match();
|
||||
match1 = gra.leftMatch;
|
||||
match2 = gra.rightMatch;
|
||||
if (have_exchange) swap(match1, match2);
|
||||
}
|
||||
302
algorithms/lane_ufld/code.embedded.bak/UFLD/evaluation/culane/src/evaluate.cpp
Executable file
302
algorithms/lane_ufld/code.embedded.bak/UFLD/evaluation/culane/src/evaluate.cpp
Executable file
@@ -0,0 +1,302 @@
|
||||
/*************************************************************************
|
||||
> File Name: evaluate.cpp
|
||||
> Author: Xingang Pan, Jun Li
|
||||
> Mail: px117@ie.cuhk.edu.hk
|
||||
> Created Time: 2016年07月14日 星期四 18时28分45秒
|
||||
************************************************************************/
|
||||
|
||||
#include "counter.hpp"
|
||||
#include "spline.hpp"
|
||||
#if __linux__
|
||||
#include <unistd.h>
|
||||
#elif _MSC_VER
|
||||
#include "getopt.h"
|
||||
#endif
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
void help(void)
|
||||
{
|
||||
cout<<"./evaluate [OPTIONS]"<<endl;
|
||||
cout<<"-h : print usage help"<<endl;
|
||||
cout<<"-a : directory for annotation files (default: /data/driving/eval_data/anno_label/)"<<endl;
|
||||
cout<<"-d : directory for detection files (default: /data/driving/eval_data/predict_label/)"<<endl;
|
||||
cout<<"-i : directory for image files (default: /data/driving/eval_data/img/)"<<endl;
|
||||
cout<<"-l : list of images used for evaluation (default: /data/driving/eval_data/img/all.txt)"<<endl;
|
||||
cout<<"-w : width of the lanes (default: 10)"<<endl;
|
||||
cout<<"-t : threshold of iou (default: 0.4)"<<endl;
|
||||
cout<<"-c : cols (max image width) (default: 1920)"<<endl;
|
||||
cout<<"-r : rows (max image height) (default: 1080)"<<endl;
|
||||
cout<<"-s : show visualization"<<endl;
|
||||
cout<<"-f : start frame in the test set (default: 1)"<<endl;
|
||||
}
|
||||
|
||||
|
||||
void read_lane_file(const string &file_name, vector<vector<Point2f> > &lanes);
|
||||
void visualize(string &full_im_name, vector<vector<Point2f> > &anno_lanes, vector<vector<Point2f> > &detect_lanes, vector<int> anno_match, int width_lane);
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// process params
|
||||
string anno_dir = "/data/driving/eval_data/anno_label/";
|
||||
string detect_dir = "/data/driving/eval_data/predict_label/";
|
||||
string im_dir = "/data/driving/eval_data/img/";
|
||||
string list_im_file = "/data/driving/eval_data/img/all.txt";
|
||||
string output_file = "./output.txt";
|
||||
int width_lane = 10;
|
||||
double iou_threshold = 0.4;
|
||||
int im_width = 1920;
|
||||
int im_height = 1080;
|
||||
int oc;
|
||||
bool show = false;
|
||||
int frame = 1;
|
||||
while((oc = getopt(argc, argv, "ha:d:i:l:w:t:c:r:sf:o:")) != -1)
|
||||
{
|
||||
switch(oc)
|
||||
{
|
||||
case 'h':
|
||||
help();
|
||||
return 0;
|
||||
case 'a':
|
||||
anno_dir = optarg;
|
||||
break;
|
||||
case 'd':
|
||||
detect_dir = optarg;
|
||||
break;
|
||||
case 'i':
|
||||
im_dir = optarg;
|
||||
break;
|
||||
case 'l':
|
||||
list_im_file = optarg;
|
||||
break;
|
||||
case 'w':
|
||||
width_lane = atoi(optarg);
|
||||
break;
|
||||
case 't':
|
||||
iou_threshold = atof(optarg);
|
||||
break;
|
||||
case 'c':
|
||||
im_width = atoi(optarg);
|
||||
break;
|
||||
case 'r':
|
||||
im_height = atoi(optarg);
|
||||
break;
|
||||
case 's':
|
||||
show = true;
|
||||
break;
|
||||
case 'f':
|
||||
frame = atoi(optarg);
|
||||
break;
|
||||
case 'o':
|
||||
output_file = optarg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cout<<"------------Configuration---------"<<endl;
|
||||
cout<<"anno_dir: "<<anno_dir<<endl;
|
||||
cout<<"detect_dir: "<<detect_dir<<endl;
|
||||
cout<<"im_dir: "<<im_dir<<endl;
|
||||
cout<<"list_im_file: "<<list_im_file<<endl;
|
||||
cout<<"width_lane: "<<width_lane<<endl;
|
||||
cout<<"iou_threshold: "<<iou_threshold<<endl;
|
||||
cout<<"im_width: "<<im_width<<endl;
|
||||
cout<<"im_height: "<<im_height<<endl;
|
||||
cout<<"-----------------------------------"<<endl;
|
||||
cout<<"Evaluating the results..."<<endl;
|
||||
// this is the max_width and max_height
|
||||
|
||||
if(width_lane<1)
|
||||
{
|
||||
cerr<<"width_lane must be positive"<<endl;
|
||||
help();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
ifstream ifs_im_list(list_im_file, ios::in);
|
||||
if(ifs_im_list.fail())
|
||||
{
|
||||
cerr<<"Error: file "<<list_im_file<<" not exist!"<<endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Counter counter(im_width, im_height, iou_threshold, width_lane);
|
||||
|
||||
vector<int> anno_match;
|
||||
string sub_im_name;
|
||||
// pre-load filelist
|
||||
vector<string> filelists;
|
||||
while (getline(ifs_im_list, sub_im_name)) {
|
||||
filelists.push_back(sub_im_name);
|
||||
}
|
||||
ifs_im_list.close();
|
||||
|
||||
vector<tuple<vector<int>, long, long, long, long>> tuple_lists;
|
||||
tuple_lists.resize(filelists.size());
|
||||
|
||||
#pragma omp parallel for
|
||||
for (int i = 0; i < filelists.size(); i++)
|
||||
{
|
||||
auto sub_im_name = filelists[i];
|
||||
string full_im_name = im_dir + sub_im_name;
|
||||
string sub_txt_name = sub_im_name.substr(0, sub_im_name.find_last_of(".")) + ".lines.txt";
|
||||
string anno_file_name = anno_dir + sub_txt_name;
|
||||
string detect_file_name = detect_dir + sub_txt_name;
|
||||
vector<vector<Point2f> > anno_lanes;
|
||||
vector<vector<Point2f> > detect_lanes;
|
||||
read_lane_file(anno_file_name, anno_lanes);
|
||||
read_lane_file(detect_file_name, detect_lanes);
|
||||
//cerr<<count<<": "<<full_im_name<<endl;
|
||||
tuple_lists[i] = counter.count_im_pair(anno_lanes, detect_lanes);
|
||||
if (show)
|
||||
{
|
||||
auto anno_match = get<0>(tuple_lists[i]);
|
||||
visualize(full_im_name, anno_lanes, detect_lanes, anno_match, width_lane);
|
||||
waitKey(0);
|
||||
}
|
||||
}
|
||||
|
||||
long tp = 0, fp = 0, tn = 0, fn = 0;
|
||||
for (auto result: tuple_lists) {
|
||||
tp += get<1>(result);
|
||||
fp += get<2>(result);
|
||||
// tn = get<3>(result);
|
||||
fn += get<4>(result);
|
||||
}
|
||||
counter.setTP(tp);
|
||||
counter.setFP(fp);
|
||||
counter.setFN(fn);
|
||||
|
||||
double precision = counter.get_precision();
|
||||
double recall = counter.get_recall();
|
||||
double F = 2 * precision * recall / (precision + recall);
|
||||
cerr<<"finished process file"<<endl;
|
||||
cout<<"precision: "<<precision<<endl;
|
||||
cout<<"recall: "<<recall<<endl;
|
||||
cout<<"Fmeasure: "<<F<<endl;
|
||||
cout<<"----------------------------------"<<endl;
|
||||
|
||||
ofstream ofs_out_file;
|
||||
ofs_out_file.open(output_file, ios::out);
|
||||
ofs_out_file<<"file: "<<output_file<<endl;
|
||||
ofs_out_file<<"tp: "<<counter.getTP()<<" fp: "<<counter.getFP()<<" fn: "<<counter.getFN()<<endl;
|
||||
ofs_out_file<<"precision: "<<precision<<endl;
|
||||
ofs_out_file<<"recall: "<<recall<<endl;
|
||||
ofs_out_file<<"Fmeasure: "<<F<<endl<<endl;
|
||||
ofs_out_file.close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void read_lane_file(const string &file_name, vector<vector<Point2f> > &lanes)
|
||||
{
|
||||
lanes.clear();
|
||||
ifstream ifs_lane(file_name, ios::in);
|
||||
if(ifs_lane.fail())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string str_line;
|
||||
while(getline(ifs_lane, str_line))
|
||||
{
|
||||
vector<Point2f> curr_lane;
|
||||
stringstream ss;
|
||||
ss<<str_line;
|
||||
double x,y;
|
||||
while(ss>>x>>y)
|
||||
{
|
||||
curr_lane.push_back(Point2f(x, y));
|
||||
}
|
||||
lanes.push_back(curr_lane);
|
||||
}
|
||||
|
||||
ifs_lane.close();
|
||||
}
|
||||
|
||||
void visualize(string &full_im_name, vector<vector<Point2f> > &anno_lanes, vector<vector<Point2f> > &detect_lanes, vector<int> anno_match, int width_lane)
|
||||
{
|
||||
Mat img = imread(full_im_name, 1);
|
||||
Mat img2 = imread(full_im_name, 1);
|
||||
vector<Point2f> curr_lane;
|
||||
vector<Point2f> p_interp;
|
||||
Spline splineSolver;
|
||||
Scalar color_B = Scalar(255, 0, 0);
|
||||
Scalar color_G = Scalar(0, 255, 0);
|
||||
Scalar color_R = Scalar(0, 0, 255);
|
||||
Scalar color_P = Scalar(255, 0, 255);
|
||||
Scalar color;
|
||||
for (int i=0; i<anno_lanes.size(); i++)
|
||||
{
|
||||
curr_lane = anno_lanes[i];
|
||||
if(curr_lane.size() == 2)
|
||||
{
|
||||
p_interp = curr_lane;
|
||||
}
|
||||
else
|
||||
{
|
||||
p_interp = splineSolver.splineInterpTimes(curr_lane, 50);
|
||||
}
|
||||
if (anno_match[i] >= 0)
|
||||
{
|
||||
color = color_G;
|
||||
}
|
||||
else
|
||||
{
|
||||
color = color_G;
|
||||
}
|
||||
for (int n=0; n<p_interp.size()-1; n++)
|
||||
{
|
||||
line(img, p_interp[n], p_interp[n+1], color, width_lane);
|
||||
line(img2, p_interp[n], p_interp[n+1], color, 2);
|
||||
}
|
||||
}
|
||||
bool detected;
|
||||
for (int i=0; i<detect_lanes.size(); i++)
|
||||
{
|
||||
detected = false;
|
||||
curr_lane = detect_lanes[i];
|
||||
if(curr_lane.size() == 2)
|
||||
{
|
||||
p_interp = curr_lane;
|
||||
}
|
||||
else
|
||||
{
|
||||
p_interp = splineSolver.splineInterpTimes(curr_lane, 50);
|
||||
}
|
||||
for (int n=0; n<anno_lanes.size(); n++)
|
||||
{
|
||||
if (anno_match[n] == i)
|
||||
{
|
||||
detected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (detected == true)
|
||||
{
|
||||
color = color_B;
|
||||
}
|
||||
else
|
||||
{
|
||||
color = color_R;
|
||||
}
|
||||
for (int n=0; n<p_interp.size()-1; n++)
|
||||
{
|
||||
line(img, p_interp[n], p_interp[n+1], color, width_lane);
|
||||
line(img2, p_interp[n], p_interp[n+1], color, 2);
|
||||
}
|
||||
}
|
||||
namedWindow("visualize", 1);
|
||||
imshow("visualize", img);
|
||||
namedWindow("visualize2", 1);
|
||||
imshow("visualize2", img2);
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*************************************************************************
|
||||
> File Name: lane_compare.cpp
|
||||
> Author: Xingang Pan, Jun Li
|
||||
> Mail: px117@ie.cuhk.edu.hk
|
||||
> Created Time: Fri Jul 15 10:26:32 2016
|
||||
************************************************************************/
|
||||
|
||||
#include "lane_compare.hpp"
|
||||
|
||||
double LaneCompare::get_lane_similarity(const vector<Point2f> &lane1, const vector<Point2f> &lane2)
|
||||
{
|
||||
if(lane1.size()<2 || lane2.size()<2)
|
||||
{
|
||||
cerr<<"lane size must be greater or equal to 2"<<endl;
|
||||
return 0;
|
||||
}
|
||||
Mat im1 = Mat::zeros(im_height, im_width, CV_8UC1);
|
||||
Mat im2 = Mat::zeros(im_height, im_width, CV_8UC1);
|
||||
// draw lines on im1 and im2
|
||||
vector<Point2f> p_interp1;
|
||||
vector<Point2f> p_interp2;
|
||||
if(lane1.size() == 2)
|
||||
{
|
||||
p_interp1 = lane1;
|
||||
}
|
||||
else
|
||||
{
|
||||
p_interp1 = splineSolver.splineInterpTimes(lane1, 50);
|
||||
}
|
||||
|
||||
if(lane2.size() == 2)
|
||||
{
|
||||
p_interp2 = lane2;
|
||||
}
|
||||
else
|
||||
{
|
||||
p_interp2 = splineSolver.splineInterpTimes(lane2, 50);
|
||||
}
|
||||
|
||||
Scalar color_white = Scalar(1);
|
||||
for(int n=0; n<p_interp1.size()-1; n++)
|
||||
{
|
||||
line(im1, p_interp1[n], p_interp1[n+1], color_white, lane_width);
|
||||
}
|
||||
for(int n=0; n<p_interp2.size()-1; n++)
|
||||
{
|
||||
line(im2, p_interp2[n], p_interp2[n+1], color_white, lane_width);
|
||||
}
|
||||
|
||||
double sum_1 = cv::sum(im1).val[0];
|
||||
double sum_2 = cv::sum(im2).val[0];
|
||||
double inter_sum = cv::sum(im1.mul(im2)).val[0];
|
||||
double union_sum = sum_1 + sum_2 - inter_sum;
|
||||
double iou = inter_sum / union_sum;
|
||||
return iou;
|
||||
}
|
||||
|
||||
|
||||
// resize the lane from Size(curr_width, curr_height) to Size(im_width, im_height)
|
||||
void LaneCompare::resize_lane(vector<Point2f> &curr_lane, int curr_width, int curr_height)
|
||||
{
|
||||
if(curr_width == im_width && curr_height == im_height)
|
||||
{
|
||||
return;
|
||||
}
|
||||
double x_scale = im_width/(double)curr_width;
|
||||
double y_scale = im_height/(double)curr_height;
|
||||
for(int n=0; n<curr_lane.size(); n++)
|
||||
{
|
||||
curr_lane[n] = Point2f(curr_lane[n].x*x_scale, curr_lane[n].y*y_scale);
|
||||
}
|
||||
}
|
||||
|
||||
178
algorithms/lane_ufld/code.embedded.bak/UFLD/evaluation/culane/src/spline.cpp
Executable file
178
algorithms/lane_ufld/code.embedded.bak/UFLD/evaluation/culane/src/spline.cpp
Executable file
@@ -0,0 +1,178 @@
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "spline.hpp"
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
vector<Point2f> Spline::splineInterpTimes(const vector<Point2f>& tmp_line, int times) {
|
||||
vector<Point2f> res;
|
||||
|
||||
if(tmp_line.size() == 2) {
|
||||
double x1 = tmp_line[0].x;
|
||||
double y1 = tmp_line[0].y;
|
||||
double x2 = tmp_line[1].x;
|
||||
double y2 = tmp_line[1].y;
|
||||
|
||||
for (int k = 0; k <= times; k++) {
|
||||
double xi = x1 + double((x2 - x1) * k) / times;
|
||||
double yi = y1 + double((y2 - y1) * k) / times;
|
||||
res.push_back(Point2f(xi, yi));
|
||||
}
|
||||
}
|
||||
|
||||
else if(tmp_line.size() > 2)
|
||||
{
|
||||
vector<Func> tmp_func;
|
||||
tmp_func = this->cal_fun(tmp_line);
|
||||
if (tmp_func.empty()) {
|
||||
cout << "in splineInterpTimes: cal_fun failed" << endl;
|
||||
return res;
|
||||
}
|
||||
for(int j = 0; j < tmp_func.size(); j++)
|
||||
{
|
||||
double delta = tmp_func[j].h / times;
|
||||
for(int k = 0; k < times; k++)
|
||||
{
|
||||
double t1 = delta*k;
|
||||
double x1 = tmp_func[j].a_x + tmp_func[j].b_x*t1 + tmp_func[j].c_x*pow(t1,2) + tmp_func[j].d_x*pow(t1,3);
|
||||
double y1 = tmp_func[j].a_y + tmp_func[j].b_y*t1 + tmp_func[j].c_y*pow(t1,2) + tmp_func[j].d_y*pow(t1,3);
|
||||
res.push_back(Point2f(x1, y1));
|
||||
}
|
||||
}
|
||||
res.push_back(tmp_line[tmp_line.size() - 1]);
|
||||
}
|
||||
else {
|
||||
cerr << "in splineInterpTimes: not enough points" << endl;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
vector<Point2f> Spline::splineInterpStep(vector<Point2f> tmp_line, double step) {
|
||||
vector<Point2f> res;
|
||||
/*
|
||||
if (tmp_line.size() == 2) {
|
||||
double x1 = tmp_line[0].x;
|
||||
double y1 = tmp_line[0].y;
|
||||
double x2 = tmp_line[1].x;
|
||||
double y2 = tmp_line[1].y;
|
||||
|
||||
for (double yi = std::min(y1, y2); yi < std::max(y1, y2); yi += step) {
|
||||
double xi;
|
||||
if (yi == y1) xi = x1;
|
||||
else xi = (x2 - x1) / (y2 - y1) * (yi - y1) + x1;
|
||||
res.push_back(Point2f(xi, yi));
|
||||
}
|
||||
}*/
|
||||
if (tmp_line.size() == 2) {
|
||||
double x1 = tmp_line[0].x;
|
||||
double y1 = tmp_line[0].y;
|
||||
double x2 = tmp_line[1].x;
|
||||
double y2 = tmp_line[1].y;
|
||||
tmp_line[1].x = (x1 + x2) / 2;
|
||||
tmp_line[1].y = (y1 + y2) / 2;
|
||||
tmp_line.push_back(Point2f(x2, y2));
|
||||
}
|
||||
if (tmp_line.size() > 2) {
|
||||
vector<Func> tmp_func;
|
||||
tmp_func = this->cal_fun(tmp_line);
|
||||
double ystart = tmp_line[0].y;
|
||||
double yend = tmp_line[tmp_line.size() - 1].y;
|
||||
bool down;
|
||||
if (ystart < yend) down = 1;
|
||||
else down = 0;
|
||||
if (tmp_func.empty()) {
|
||||
cerr << "in splineInterpStep: cal_fun failed" << endl;
|
||||
}
|
||||
|
||||
for(int j = 0; j < tmp_func.size(); j++)
|
||||
{
|
||||
for(double t1 = 0; t1 < tmp_func[j].h; t1 += step)
|
||||
{
|
||||
double x1 = tmp_func[j].a_x + tmp_func[j].b_x*t1 + tmp_func[j].c_x*pow(t1,2) + tmp_func[j].d_x*pow(t1,3);
|
||||
double y1 = tmp_func[j].a_y + tmp_func[j].b_y*t1 + tmp_func[j].c_y*pow(t1,2) + tmp_func[j].d_y*pow(t1,3);
|
||||
res.push_back(Point2f(x1, y1));
|
||||
}
|
||||
}
|
||||
res.push_back(tmp_line[tmp_line.size() - 1]);
|
||||
}
|
||||
else {
|
||||
cerr << "in splineInterpStep: not enough points" << endl;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
vector<Func> Spline::cal_fun(const vector<Point2f> &point_v)
|
||||
{
|
||||
vector<Func> func_v;
|
||||
int n = point_v.size();
|
||||
if(n<=2) {
|
||||
cout << "in cal_fun: point number less than 3" << endl;
|
||||
return func_v;
|
||||
}
|
||||
|
||||
func_v.resize(point_v.size()-1);
|
||||
|
||||
vector<double> Mx(n);
|
||||
vector<double> My(n);
|
||||
vector<double> A(n-2);
|
||||
vector<double> B(n-2);
|
||||
vector<double> C(n-2);
|
||||
vector<double> Dx(n-2);
|
||||
vector<double> Dy(n-2);
|
||||
vector<double> h(n-1);
|
||||
//vector<func> func_v(n-1);
|
||||
|
||||
for(int i = 0; i < n-1; i++)
|
||||
{
|
||||
h[i] = sqrt(pow(point_v[i+1].x - point_v[i].x, 2) + pow(point_v[i+1].y - point_v[i].y, 2));
|
||||
}
|
||||
|
||||
for(int i = 0; i < n-2; i++)
|
||||
{
|
||||
A[i] = h[i];
|
||||
B[i] = 2*(h[i]+h[i+1]);
|
||||
C[i] = h[i+1];
|
||||
|
||||
Dx[i] = 6*( (point_v[i+2].x - point_v[i+1].x)/h[i+1] - (point_v[i+1].x - point_v[i].x)/h[i] );
|
||||
Dy[i] = 6*( (point_v[i+2].y - point_v[i+1].y)/h[i+1] - (point_v[i+1].y - point_v[i].y)/h[i] );
|
||||
}
|
||||
|
||||
//TDMA
|
||||
C[0] = C[0] / B[0];
|
||||
Dx[0] = Dx[0] / B[0];
|
||||
Dy[0] = Dy[0] / B[0];
|
||||
for(int i = 1; i < n-2; i++)
|
||||
{
|
||||
double tmp = B[i] - A[i]*C[i-1];
|
||||
C[i] = C[i] / tmp;
|
||||
Dx[i] = (Dx[i] - A[i]*Dx[i-1]) / tmp;
|
||||
Dy[i] = (Dy[i] - A[i]*Dy[i-1]) / tmp;
|
||||
}
|
||||
Mx[n-2] = Dx[n-3];
|
||||
My[n-2] = Dy[n-3];
|
||||
for(int i = n-4; i >= 0; i--)
|
||||
{
|
||||
Mx[i+1] = Dx[i] - C[i]*Mx[i+2];
|
||||
My[i+1] = Dy[i] - C[i]*My[i+2];
|
||||
}
|
||||
|
||||
Mx[0] = 0;
|
||||
Mx[n-1] = 0;
|
||||
My[0] = 0;
|
||||
My[n-1] = 0;
|
||||
|
||||
for(int i = 0; i < n-1; i++)
|
||||
{
|
||||
func_v[i].a_x = point_v[i].x;
|
||||
func_v[i].b_x = (point_v[i+1].x - point_v[i].x)/h[i] - (2*h[i]*Mx[i] + h[i]*Mx[i+1]) / 6;
|
||||
func_v[i].c_x = Mx[i]/2;
|
||||
func_v[i].d_x = (Mx[i+1] - Mx[i]) / (6*h[i]);
|
||||
|
||||
func_v[i].a_y = point_v[i].y;
|
||||
func_v[i].b_y = (point_v[i+1].y - point_v[i].y)/h[i] - (2*h[i]*My[i] + h[i]*My[i+1]) / 6;
|
||||
func_v[i].c_y = My[i]/2;
|
||||
func_v[i].d_y = (My[i+1] - My[i]) / (6*h[i]);
|
||||
|
||||
func_v[i].h = h[i];
|
||||
}
|
||||
return func_v;
|
||||
}
|
||||
244
algorithms/lane_ufld/code.embedded.bak/UFLD/evaluation/eval_wrapper.py
Executable file
244
algorithms/lane_ufld/code.embedded.bak/UFLD/evaluation/eval_wrapper.py
Executable file
@@ -0,0 +1,244 @@
|
||||
|
||||
from data.dataloader import get_test_loader
|
||||
from evaluation.tusimple.lane import LaneEval
|
||||
from utils.dist_utils import is_main_process, dist_print, get_rank, get_world_size, dist_tqdm, synchronize
|
||||
import os, json, torch, scipy
|
||||
import numpy as np
|
||||
import platform
|
||||
|
||||
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
||||
def generate_lines(out, shape, names, output_path, griding_num, localization_type='abs', flip_updown=False):
|
||||
|
||||
col_sample = np.linspace(0, shape[1] - 1, griding_num)
|
||||
col_sample_w = col_sample[1] - col_sample[0]
|
||||
|
||||
for j in range(out.shape[0]):
|
||||
out_j = out[j].data.cpu().numpy()
|
||||
if flip_updown:
|
||||
out_j = out_j[:, ::-1, :]
|
||||
if localization_type == 'abs':
|
||||
out_j = np.argmax(out_j, axis=0)
|
||||
out_j[out_j == griding_num] = -1
|
||||
out_j = out_j + 1
|
||||
elif localization_type == 'rel':
|
||||
prob = scipy.special.softmax(out_j[:-1, :, :], axis=0)
|
||||
idx = np.arange(griding_num) + 1
|
||||
idx = idx.reshape(-1, 1, 1)
|
||||
loc = np.sum(prob * idx, axis=0)
|
||||
out_j = np.argmax(out_j, axis=0)
|
||||
loc[out_j == griding_num] = 0
|
||||
out_j = loc
|
||||
else:
|
||||
raise NotImplementedError
|
||||
name = names[j]
|
||||
|
||||
line_save_path = os.path.join(output_path, name[:-3] + 'lines.txt')
|
||||
save_dir, _ = os.path.split(line_save_path)
|
||||
if not os.path.exists(save_dir):
|
||||
os.makedirs(save_dir)
|
||||
with open(line_save_path, 'w') as fp:
|
||||
for i in range(out_j.shape[1]):
|
||||
if np.sum(out_j[:, i] != 0) > 2:
|
||||
for k in range(out_j.shape[0]):
|
||||
if out_j[k, i] > 0:
|
||||
fp.write(
|
||||
'%d %d ' % (int(out_j[k, i] * col_sample_w * 1640 / 800) - 1, int(590 - k * 20) - 1))
|
||||
fp.write('\n')
|
||||
|
||||
def run_test(net, data_root, exp_name, work_dir, griding_num, use_aux, distributed, batch_size=8, test_list=None):
|
||||
# torch.backends.cudnn.benchmark = True
|
||||
output_path = os.path.join(work_dir, exp_name)
|
||||
if not os.path.exists(output_path) and is_main_process():
|
||||
os.mkdir(output_path)
|
||||
synchronize()
|
||||
loader = get_test_loader(batch_size, data_root, 'CULane', distributed, test_list=test_list)
|
||||
# import pdb;pdb.set_trace()
|
||||
for i, data in enumerate(dist_tqdm(loader)):
|
||||
imgs, names = data
|
||||
imgs = imgs.cuda()
|
||||
with torch.no_grad():
|
||||
out = net(imgs)
|
||||
if len(out) == 2 and use_aux:
|
||||
out, seg_out = out
|
||||
|
||||
generate_lines(out,imgs[0,0].shape,names,output_path,griding_num,localization_type = 'rel',flip_updown = True)
|
||||
def generate_tusimple_lines(out,shape,griding_num,localization_type='rel'):
|
||||
|
||||
out = out.data.cpu().numpy()
|
||||
out_loc = np.argmax(out,axis=0)
|
||||
|
||||
if localization_type == 'rel':
|
||||
prob = scipy.special.softmax(out[:-1, :, :], axis=0)
|
||||
idx = np.arange(griding_num)
|
||||
idx = idx.reshape(-1, 1, 1)
|
||||
|
||||
loc = np.sum(prob * idx, axis=0)
|
||||
|
||||
loc[out_loc == griding_num] = griding_num
|
||||
out_loc = loc
|
||||
lanes = []
|
||||
for i in range(out_loc.shape[1]):
|
||||
out_i = out_loc[:,i]
|
||||
lane = [int(round((loc + 0.5) * 1280.0 / (griding_num - 1))) if loc != griding_num else -2 for loc in out_i]
|
||||
lanes.append(lane)
|
||||
return lanes
|
||||
|
||||
def run_test_tusimple(net, data_root, work_dir, exp_name, griding_num, use_aux, distributed, batch_size=1, test_list=None):
|
||||
output_path = os.path.join(work_dir,exp_name+'.%d.txt'% get_rank())
|
||||
fp = open(output_path,'w')
|
||||
loader = get_test_loader(batch_size, data_root, 'Tusimple', distributed, test_list=test_list)
|
||||
for i,data in enumerate(dist_tqdm(loader)):
|
||||
imgs,names = data
|
||||
# imgs = imgs.cuda()
|
||||
imgs = imgs.to(device)
|
||||
with torch.no_grad():
|
||||
out = net(imgs)
|
||||
if len(out) == 2 and use_aux:
|
||||
out = out[0]
|
||||
for i,name in enumerate(names):
|
||||
tmp_dict = {}
|
||||
tmp_dict['lanes'] = generate_tusimple_lines(out[i],imgs[0,0].shape,griding_num)
|
||||
tmp_dict['h_samples'] = [160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260,
|
||||
270, 280, 290, 300, 310, 320, 330, 340, 350, 360, 370, 380, 390, 400, 410, 420,
|
||||
430, 440, 450, 460, 470, 480, 490, 500, 510, 520, 530, 540, 550, 560, 570, 580,
|
||||
590, 600, 610, 620, 630, 640, 650, 660, 670, 680, 690, 700, 710]
|
||||
tmp_dict['raw_file'] = name
|
||||
tmp_dict['run_time'] = 10
|
||||
json_str = json.dumps(tmp_dict)
|
||||
|
||||
fp.write(json_str+'\n')
|
||||
fp.close()
|
||||
|
||||
def combine_tusimple_test(work_dir,exp_name):
|
||||
size = get_world_size()
|
||||
all_res = []
|
||||
for i in range(size):
|
||||
output_path = os.path.join(work_dir,exp_name+'.%d.txt'% i)
|
||||
with open(output_path, 'r') as fp:
|
||||
res = fp.readlines()
|
||||
all_res.extend(res)
|
||||
names = set()
|
||||
all_res_no_dup = []
|
||||
for i, res in enumerate(all_res):
|
||||
pos = res.find('clips')
|
||||
name = res[pos:].split('\"')[0]
|
||||
if name not in names:
|
||||
names.add(name)
|
||||
all_res_no_dup.append(res)
|
||||
|
||||
output_path = os.path.join(work_dir,exp_name+'.txt')
|
||||
with open(output_path, 'w') as fp:
|
||||
fp.writelines(all_res_no_dup)
|
||||
|
||||
|
||||
def eval_lane(net, dataset, data_root, work_dir, griding_num, use_aux, distributed, test_list=None, skip_eval=False):
|
||||
net.eval()
|
||||
if dataset == 'CULane':
|
||||
run_test(net, data_root, 'culane_eval_tmp', work_dir, griding_num, use_aux, distributed, test_list=test_list)
|
||||
synchronize() # wait for all results
|
||||
if is_main_process():
|
||||
res = call_culane_eval(data_root, 'culane_eval_tmp', work_dir)
|
||||
TP,FP,FN = 0,0,0
|
||||
for k, v in res.items():
|
||||
val = float(v['Fmeasure']) if 'nan' not in v['Fmeasure'] else 0
|
||||
val_tp,val_fp,val_fn = int(v['tp']),int(v['fp']),int(v['fn'])
|
||||
TP += val_tp
|
||||
FP += val_fp
|
||||
FN += val_fn
|
||||
dist_print(k,val)
|
||||
P = TP * 1.0/(TP + FP)
|
||||
R = TP * 1.0/(TP + FN)
|
||||
F = 2*P*R/(P + R)
|
||||
dist_print(F)
|
||||
synchronize()
|
||||
|
||||
elif dataset == 'Tusimple':
|
||||
exp_name = 'tusimple_eval_tmp'
|
||||
run_test_tusimple(net, data_root, work_dir, exp_name, griding_num, use_aux, distributed, test_list=test_list)
|
||||
synchronize() # wait for all results
|
||||
if is_main_process():
|
||||
pred_path = os.path.join(work_dir, exp_name + '.0.txt')
|
||||
label_json = os.path.join(data_root, 'test_label.json')
|
||||
if skip_eval or not os.path.isfile(label_json):
|
||||
dist_print('skip TuSimple metrics (no test_label.json); predictions:', pred_path)
|
||||
else:
|
||||
res = LaneEval.bench_one_submit(pred_path, label_json)
|
||||
res = json.loads(res)
|
||||
for r in res:
|
||||
dist_print(r['name'], r['value'])
|
||||
synchronize()
|
||||
|
||||
|
||||
def read_helper(path):
|
||||
lines = open(path, 'r').readlines()[1:]
|
||||
lines = ' '.join(lines)
|
||||
values = lines.split(' ')[1::2]
|
||||
keys = lines.split(' ')[0::2]
|
||||
keys = [key[:-1] for key in keys]
|
||||
res = {k : v for k,v in zip(keys,values)}
|
||||
return res
|
||||
|
||||
def call_culane_eval(data_dir, exp_name,output_path):
|
||||
if data_dir[-1] != '/':
|
||||
data_dir = data_dir + '/'
|
||||
detect_dir=os.path.join(output_path,exp_name)+'/'
|
||||
|
||||
w_lane=30
|
||||
iou=0.5; # Set iou to 0.3 or 0.5
|
||||
im_w=1640
|
||||
im_h=590
|
||||
frame=1
|
||||
list0 = os.path.join(data_dir,'list/test_split/test0_normal.txt')
|
||||
list1 = os.path.join(data_dir,'list/test_split/test1_crowd.txt')
|
||||
list2 = os.path.join(data_dir,'list/test_split/test2_hlight.txt')
|
||||
list3 = os.path.join(data_dir,'list/test_split/test3_shadow.txt')
|
||||
list4 = os.path.join(data_dir,'list/test_split/test4_noline.txt')
|
||||
list5 = os.path.join(data_dir,'list/test_split/test5_arrow.txt')
|
||||
list6 = os.path.join(data_dir,'list/test_split/test6_curve.txt')
|
||||
list7 = os.path.join(data_dir,'list/test_split/test7_cross.txt')
|
||||
list8 = os.path.join(data_dir,'list/test_split/test8_night.txt')
|
||||
if not os.path.exists(os.path.join(output_path,'txt')):
|
||||
os.mkdir(os.path.join(output_path,'txt'))
|
||||
out0 = os.path.join(output_path,'txt','out0_normal.txt')
|
||||
out1=os.path.join(output_path,'txt','out1_crowd.txt')
|
||||
out2=os.path.join(output_path,'txt','out2_hlight.txt')
|
||||
out3=os.path.join(output_path,'txt','out3_shadow.txt')
|
||||
out4=os.path.join(output_path,'txt','out4_noline.txt')
|
||||
out5=os.path.join(output_path,'txt','out5_arrow.txt')
|
||||
out6=os.path.join(output_path,'txt','out6_curve.txt')
|
||||
out7=os.path.join(output_path,'txt','out7_cross.txt')
|
||||
out8=os.path.join(output_path,'txt','out8_night.txt')
|
||||
|
||||
eval_cmd = './evaluation/culane/evaluate'
|
||||
if platform.system() == 'Windows':
|
||||
eval_cmd = eval_cmd.replace('/', os.sep)
|
||||
|
||||
# print('./evaluate -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(data_dir,detect_dir,data_dir,list0,w_lane,iou,im_w,im_h,frame,out0))
|
||||
os.system('%s -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(eval_cmd,data_dir,detect_dir,data_dir,list0,w_lane,iou,im_w,im_h,frame,out0))
|
||||
# print('./evaluate -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(data_dir,detect_dir,data_dir,list1,w_lane,iou,im_w,im_h,frame,out1))
|
||||
os.system('%s -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(eval_cmd,data_dir,detect_dir,data_dir,list1,w_lane,iou,im_w,im_h,frame,out1))
|
||||
# print('./evaluate -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(data_dir,detect_dir,data_dir,list2,w_lane,iou,im_w,im_h,frame,out2))
|
||||
os.system('%s -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(eval_cmd,data_dir,detect_dir,data_dir,list2,w_lane,iou,im_w,im_h,frame,out2))
|
||||
# print('./evaluate -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(data_dir,detect_dir,data_dir,list3,w_lane,iou,im_w,im_h,frame,out3))
|
||||
os.system('%s -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(eval_cmd,data_dir,detect_dir,data_dir,list3,w_lane,iou,im_w,im_h,frame,out3))
|
||||
# print('./evaluate -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(data_dir,detect_dir,data_dir,list4,w_lane,iou,im_w,im_h,frame,out4))
|
||||
os.system('%s -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(eval_cmd,data_dir,detect_dir,data_dir,list4,w_lane,iou,im_w,im_h,frame,out4))
|
||||
# print('./evaluate -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(data_dir,detect_dir,data_dir,list5,w_lane,iou,im_w,im_h,frame,out5))
|
||||
os.system('%s -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(eval_cmd,data_dir,detect_dir,data_dir,list5,w_lane,iou,im_w,im_h,frame,out5))
|
||||
# print('./evaluate -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(data_dir,detect_dir,data_dir,list6,w_lane,iou,im_w,im_h,frame,out6))
|
||||
os.system('%s -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(eval_cmd,data_dir,detect_dir,data_dir,list6,w_lane,iou,im_w,im_h,frame,out6))
|
||||
# print('./evaluate -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(data_dir,detect_dir,data_dir,list7,w_lane,iou,im_w,im_h,frame,out7))
|
||||
os.system('%s -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(eval_cmd,data_dir,detect_dir,data_dir,list7,w_lane,iou,im_w,im_h,frame,out7))
|
||||
# print('./evaluate -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(data_dir,detect_dir,data_dir,list8,w_lane,iou,im_w,im_h,frame,out8))
|
||||
os.system('%s -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(eval_cmd,data_dir,detect_dir,data_dir,list8,w_lane,iou,im_w,im_h,frame,out8))
|
||||
res_all = {}
|
||||
res_all['res_normal'] = read_helper(out0)
|
||||
res_all['res_crowd']= read_helper(out1)
|
||||
res_all['res_night']= read_helper(out8)
|
||||
res_all['res_noline'] = read_helper(out4)
|
||||
res_all['res_shadow'] = read_helper(out3)
|
||||
res_all['res_arrow']= read_helper(out5)
|
||||
res_all['res_hlight'] = read_helper(out2)
|
||||
res_all['res_curve']= read_helper(out6)
|
||||
res_all['res_cross']= read_helper(out7)
|
||||
return res_all
|
||||
238
algorithms/lane_ufld/code.embedded.bak/UFLD/evaluation/eval_wrapper0.py
Executable file
238
algorithms/lane_ufld/code.embedded.bak/UFLD/evaluation/eval_wrapper0.py
Executable file
@@ -0,0 +1,238 @@
|
||||
|
||||
from data.dataloader import get_test_loader
|
||||
from evaluation.tusimple.lane import LaneEval
|
||||
from utils.dist_utils import is_main_process, dist_print, get_rank, get_world_size, dist_tqdm, synchronize
|
||||
import os, json, torch, scipy
|
||||
import numpy as np
|
||||
import platform
|
||||
|
||||
def generate_lines(out, shape, names, output_path, griding_num, localization_type='abs', flip_updown=False):
|
||||
|
||||
col_sample = np.linspace(0, shape[1] - 1, griding_num)
|
||||
col_sample_w = col_sample[1] - col_sample[0]
|
||||
|
||||
for j in range(out.shape[0]):
|
||||
out_j = out[j].data.cpu().numpy()
|
||||
if flip_updown:
|
||||
out_j = out_j[:, ::-1, :]
|
||||
if localization_type == 'abs':
|
||||
out_j = np.argmax(out_j, axis=0)
|
||||
out_j[out_j == griding_num] = -1
|
||||
out_j = out_j + 1
|
||||
elif localization_type == 'rel':
|
||||
prob = scipy.special.softmax(out_j[:-1, :, :], axis=0)
|
||||
idx = np.arange(griding_num) + 1
|
||||
idx = idx.reshape(-1, 1, 1)
|
||||
loc = np.sum(prob * idx, axis=0)
|
||||
out_j = np.argmax(out_j, axis=0)
|
||||
loc[out_j == griding_num] = 0
|
||||
out_j = loc
|
||||
else:
|
||||
raise NotImplementedError
|
||||
name = names[j]
|
||||
|
||||
line_save_path = os.path.join(output_path, name[:-3] + 'lines.txt')
|
||||
save_dir, _ = os.path.split(line_save_path)
|
||||
if not os.path.exists(save_dir):
|
||||
os.makedirs(save_dir)
|
||||
with open(line_save_path, 'w') as fp:
|
||||
for i in range(out_j.shape[1]):
|
||||
if np.sum(out_j[:, i] != 0) > 2:
|
||||
for k in range(out_j.shape[0]):
|
||||
if out_j[k, i] > 0:
|
||||
fp.write(
|
||||
'%d %d ' % (int(out_j[k, i] * col_sample_w * 1640 / 800) - 1, int(590 - k * 20) - 1))
|
||||
fp.write('\n')
|
||||
|
||||
def run_test(net, data_root, exp_name, work_dir, griding_num, use_aux,distributed, batch_size=8):
|
||||
# torch.backends.cudnn.benchmark = True
|
||||
output_path = os.path.join(work_dir, exp_name)
|
||||
if not os.path.exists(output_path) and is_main_process():
|
||||
os.mkdir(output_path)
|
||||
synchronize()
|
||||
loader = get_test_loader(batch_size, data_root, 'CULane', distributed)
|
||||
# import pdb;pdb.set_trace()
|
||||
for i, data in enumerate(dist_tqdm(loader)):
|
||||
imgs, names = data
|
||||
imgs = imgs.cuda()
|
||||
with torch.no_grad():
|
||||
out = net(imgs)
|
||||
if len(out) == 2 and use_aux:
|
||||
out, seg_out = out
|
||||
|
||||
generate_lines(out,imgs[0,0].shape,names,output_path,griding_num,localization_type = 'rel',flip_updown = True)
|
||||
def generate_tusimple_lines(out,shape,griding_num,localization_type='rel'):
|
||||
|
||||
out = out.data.cpu().numpy()
|
||||
out_loc = np.argmax(out,axis=0)
|
||||
|
||||
if localization_type == 'rel':
|
||||
prob = scipy.special.softmax(out[:-1, :, :], axis=0)
|
||||
idx = np.arange(griding_num)
|
||||
idx = idx.reshape(-1, 1, 1)
|
||||
|
||||
loc = np.sum(prob * idx, axis=0)
|
||||
|
||||
loc[out_loc == griding_num] = griding_num
|
||||
out_loc = loc
|
||||
lanes = []
|
||||
for i in range(out_loc.shape[1]):
|
||||
out_i = out_loc[:,i]
|
||||
lane = [int(round((loc + 0.5) * 1280.0 / (griding_num - 1))) if loc != griding_num else -2 for loc in out_i]
|
||||
lanes.append(lane)
|
||||
return lanes
|
||||
|
||||
def run_test_tusimple(net,data_root,work_dir,exp_name,griding_num,use_aux, distributed,batch_size = 8):
|
||||
output_path = os.path.join(work_dir,exp_name+'.%d.txt'% get_rank())
|
||||
fp = open(output_path,'w')
|
||||
loader = get_test_loader(batch_size,data_root,'Tusimple', distributed)
|
||||
for i,data in enumerate(dist_tqdm(loader)):
|
||||
imgs,names = data
|
||||
imgs = imgs.cuda()
|
||||
with torch.no_grad():
|
||||
out = net(imgs)
|
||||
if len(out) == 2 and use_aux:
|
||||
out = out[0]
|
||||
for i,name in enumerate(names):
|
||||
tmp_dict = {}
|
||||
tmp_dict['lanes'] = generate_tusimple_lines(out[i],imgs[0,0].shape,griding_num)
|
||||
tmp_dict['h_samples'] = [160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260,
|
||||
270, 280, 290, 300, 310, 320, 330, 340, 350, 360, 370, 380, 390, 400, 410, 420,
|
||||
430, 440, 450, 460, 470, 480, 490, 500, 510, 520, 530, 540, 550, 560, 570, 580,
|
||||
590, 600, 610, 620, 630, 640, 650, 660, 670, 680, 690, 700, 710]
|
||||
tmp_dict['raw_file'] = name
|
||||
tmp_dict['run_time'] = 10
|
||||
json_str = json.dumps(tmp_dict)
|
||||
|
||||
fp.write(json_str+'\n')
|
||||
fp.close()
|
||||
|
||||
def combine_tusimple_test(work_dir,exp_name):
|
||||
size = get_world_size()
|
||||
all_res = []
|
||||
for i in range(size):
|
||||
output_path = os.path.join(work_dir,exp_name+'.%d.txt'% i)
|
||||
with open(output_path, 'r') as fp:
|
||||
res = fp.readlines()
|
||||
all_res.extend(res)
|
||||
names = set()
|
||||
all_res_no_dup = []
|
||||
for i, res in enumerate(all_res):
|
||||
pos = res.find('clips')
|
||||
name = res[pos:].split('\"')[0]
|
||||
if name not in names:
|
||||
names.add(name)
|
||||
all_res_no_dup.append(res)
|
||||
|
||||
output_path = os.path.join(work_dir,exp_name+'.txt')
|
||||
with open(output_path, 'w') as fp:
|
||||
fp.writelines(all_res_no_dup)
|
||||
|
||||
|
||||
def eval_lane(net, dataset, data_root, work_dir, griding_num, use_aux, distributed):
|
||||
net.eval()
|
||||
if dataset == 'CULane':
|
||||
run_test(net,data_root, 'culane_eval_tmp', work_dir, griding_num, use_aux, distributed)
|
||||
synchronize() # wait for all results
|
||||
if is_main_process():
|
||||
res = call_culane_eval(data_root, 'culane_eval_tmp', work_dir)
|
||||
TP,FP,FN = 0,0,0
|
||||
for k, v in res.items():
|
||||
val = float(v['Fmeasure']) if 'nan' not in v['Fmeasure'] else 0
|
||||
val_tp,val_fp,val_fn = int(v['tp']),int(v['fp']),int(v['fn'])
|
||||
TP += val_tp
|
||||
FP += val_fp
|
||||
FN += val_fn
|
||||
dist_print(k,val)
|
||||
P = TP * 1.0/(TP + FP)
|
||||
R = TP * 1.0/(TP + FN)
|
||||
F = 2*P*R/(P + R)
|
||||
dist_print(F)
|
||||
synchronize()
|
||||
|
||||
elif dataset == 'Tusimple':
|
||||
exp_name = 'tusimple_eval_tmp'
|
||||
run_test_tusimple(net, data_root, work_dir, exp_name, griding_num, use_aux, distributed)
|
||||
synchronize() # wait for all results
|
||||
if is_main_process():
|
||||
combine_tusimple_test(work_dir,exp_name)
|
||||
res = LaneEval.bench_one_submit(os.path.join(work_dir,exp_name + '.txt'),os.path.join(data_root,'test_label.json'))
|
||||
res = json.loads(res)
|
||||
for r in res:
|
||||
dist_print(r['name'], r['value'])
|
||||
synchronize()
|
||||
|
||||
|
||||
def read_helper(path):
|
||||
lines = open(path, 'r').readlines()[1:]
|
||||
lines = ' '.join(lines)
|
||||
values = lines.split(' ')[1::2]
|
||||
keys = lines.split(' ')[0::2]
|
||||
keys = [key[:-1] for key in keys]
|
||||
res = {k : v for k,v in zip(keys,values)}
|
||||
return res
|
||||
|
||||
def call_culane_eval(data_dir, exp_name,output_path):
|
||||
if data_dir[-1] != '/':
|
||||
data_dir = data_dir + '/'
|
||||
detect_dir=os.path.join(output_path,exp_name)+'/'
|
||||
|
||||
w_lane=30
|
||||
iou=0.5; # Set iou to 0.3 or 0.5
|
||||
im_w=1640
|
||||
im_h=590
|
||||
frame=1
|
||||
list0 = os.path.join(data_dir,'list/test_split/test0_normal.txt')
|
||||
list1 = os.path.join(data_dir,'list/test_split/test1_crowd.txt')
|
||||
list2 = os.path.join(data_dir,'list/test_split/test2_hlight.txt')
|
||||
list3 = os.path.join(data_dir,'list/test_split/test3_shadow.txt')
|
||||
list4 = os.path.join(data_dir,'list/test_split/test4_noline.txt')
|
||||
list5 = os.path.join(data_dir,'list/test_split/test5_arrow.txt')
|
||||
list6 = os.path.join(data_dir,'list/test_split/test6_curve.txt')
|
||||
list7 = os.path.join(data_dir,'list/test_split/test7_cross.txt')
|
||||
list8 = os.path.join(data_dir,'list/test_split/test8_night.txt')
|
||||
if not os.path.exists(os.path.join(output_path,'txt')):
|
||||
os.mkdir(os.path.join(output_path,'txt'))
|
||||
out0 = os.path.join(output_path,'txt','out0_normal.txt')
|
||||
out1=os.path.join(output_path,'txt','out1_crowd.txt')
|
||||
out2=os.path.join(output_path,'txt','out2_hlight.txt')
|
||||
out3=os.path.join(output_path,'txt','out3_shadow.txt')
|
||||
out4=os.path.join(output_path,'txt','out4_noline.txt')
|
||||
out5=os.path.join(output_path,'txt','out5_arrow.txt')
|
||||
out6=os.path.join(output_path,'txt','out6_curve.txt')
|
||||
out7=os.path.join(output_path,'txt','out7_cross.txt')
|
||||
out8=os.path.join(output_path,'txt','out8_night.txt')
|
||||
|
||||
eval_cmd = './evaluation/culane/evaluate'
|
||||
if platform.system() == 'Windows':
|
||||
eval_cmd = eval_cmd.replace('/', os.sep)
|
||||
|
||||
# print('./evaluate -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(data_dir,detect_dir,data_dir,list0,w_lane,iou,im_w,im_h,frame,out0))
|
||||
os.system('%s -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(eval_cmd,data_dir,detect_dir,data_dir,list0,w_lane,iou,im_w,im_h,frame,out0))
|
||||
# print('./evaluate -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(data_dir,detect_dir,data_dir,list1,w_lane,iou,im_w,im_h,frame,out1))
|
||||
os.system('%s -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(eval_cmd,data_dir,detect_dir,data_dir,list1,w_lane,iou,im_w,im_h,frame,out1))
|
||||
# print('./evaluate -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(data_dir,detect_dir,data_dir,list2,w_lane,iou,im_w,im_h,frame,out2))
|
||||
os.system('%s -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(eval_cmd,data_dir,detect_dir,data_dir,list2,w_lane,iou,im_w,im_h,frame,out2))
|
||||
# print('./evaluate -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(data_dir,detect_dir,data_dir,list3,w_lane,iou,im_w,im_h,frame,out3))
|
||||
os.system('%s -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(eval_cmd,data_dir,detect_dir,data_dir,list3,w_lane,iou,im_w,im_h,frame,out3))
|
||||
# print('./evaluate -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(data_dir,detect_dir,data_dir,list4,w_lane,iou,im_w,im_h,frame,out4))
|
||||
os.system('%s -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(eval_cmd,data_dir,detect_dir,data_dir,list4,w_lane,iou,im_w,im_h,frame,out4))
|
||||
# print('./evaluate -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(data_dir,detect_dir,data_dir,list5,w_lane,iou,im_w,im_h,frame,out5))
|
||||
os.system('%s -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(eval_cmd,data_dir,detect_dir,data_dir,list5,w_lane,iou,im_w,im_h,frame,out5))
|
||||
# print('./evaluate -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(data_dir,detect_dir,data_dir,list6,w_lane,iou,im_w,im_h,frame,out6))
|
||||
os.system('%s -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(eval_cmd,data_dir,detect_dir,data_dir,list6,w_lane,iou,im_w,im_h,frame,out6))
|
||||
# print('./evaluate -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(data_dir,detect_dir,data_dir,list7,w_lane,iou,im_w,im_h,frame,out7))
|
||||
os.system('%s -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(eval_cmd,data_dir,detect_dir,data_dir,list7,w_lane,iou,im_w,im_h,frame,out7))
|
||||
# print('./evaluate -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(data_dir,detect_dir,data_dir,list8,w_lane,iou,im_w,im_h,frame,out8))
|
||||
os.system('%s -a %s -d %s -i %s -l %s -w %s -t %s -c %s -r %s -f %s -o %s'%(eval_cmd,data_dir,detect_dir,data_dir,list8,w_lane,iou,im_w,im_h,frame,out8))
|
||||
res_all = {}
|
||||
res_all['res_normal'] = read_helper(out0)
|
||||
res_all['res_crowd']= read_helper(out1)
|
||||
res_all['res_night']= read_helper(out8)
|
||||
res_all['res_noline'] = read_helper(out4)
|
||||
res_all['res_shadow'] = read_helper(out3)
|
||||
res_all['res_arrow']= read_helper(out5)
|
||||
res_all['res_hlight'] = read_helper(out2)
|
||||
res_all['res_curve']= read_helper(out6)
|
||||
res_all['res_cross']= read_helper(out7)
|
||||
return res_all
|
||||
111
algorithms/lane_ufld/code.embedded.bak/UFLD/evaluation/tusimple/lane.py
Executable file
111
algorithms/lane_ufld/code.embedded.bak/UFLD/evaluation/tusimple/lane.py
Executable file
@@ -0,0 +1,111 @@
|
||||
import os
|
||||
import numpy as np
|
||||
from sklearn.linear_model import LinearRegression
|
||||
import json, shutil
|
||||
|
||||
|
||||
class LaneEval(object):
|
||||
lr = LinearRegression()
|
||||
pixel_thresh = 20
|
||||
pt_thresh = 0.85
|
||||
|
||||
@staticmethod
|
||||
def get_angle(xs, y_samples):
|
||||
xs, ys = xs[xs >= 0], y_samples[xs >= 0]
|
||||
if len(xs) > 1:
|
||||
LaneEval.lr.fit(ys[:, None], xs)
|
||||
k = LaneEval.lr.coef_[0]
|
||||
theta = np.arctan(k)
|
||||
else:
|
||||
theta = 0
|
||||
return theta
|
||||
|
||||
@staticmethod
|
||||
def line_accuracy(pred, gt, thresh):
|
||||
pred = np.array([p if p >= 0 else -100 for p in pred])
|
||||
gt = np.array([g if g >= 0 else -100 for g in gt])
|
||||
return np.sum(np.where(np.abs(pred - gt) < thresh, 1., 0.)) / len(gt)
|
||||
|
||||
@staticmethod
|
||||
def bench(pred, gt, y_samples, running_time):
|
||||
if any(len(p) != len(y_samples) for p in pred):
|
||||
raise Exception('Format of lanes error.')
|
||||
if running_time > 200 or len(gt) + 2 < len(pred):
|
||||
return 0., 0., 1.
|
||||
angles = [LaneEval.get_angle(np.array(x_gts), np.array(y_samples)) for x_gts in gt]
|
||||
threshs = [LaneEval.pixel_thresh / np.cos(angle) for angle in angles]
|
||||
line_accs = []
|
||||
fp, fn = 0., 0.
|
||||
matched = 0.
|
||||
for x_gts, thresh in zip(gt, threshs):
|
||||
accs = [LaneEval.line_accuracy(np.array(x_preds), np.array(x_gts), thresh) for x_preds in pred]
|
||||
max_acc = np.max(accs) if len(accs) > 0 else 0.
|
||||
if max_acc < LaneEval.pt_thresh:
|
||||
fn += 1
|
||||
else:
|
||||
matched += 1
|
||||
line_accs.append(max_acc)
|
||||
fp = len(pred) - matched
|
||||
if len(gt) > 4 and fn > 0:
|
||||
fn -= 1
|
||||
s = sum(line_accs)
|
||||
if len(gt) > 4:
|
||||
s -= min(line_accs)
|
||||
# print('s:', s, len(gt))
|
||||
return s / max(min(4.0, len(gt)), 1.), fp / len(pred) if len(pred) > 0 else 0., fn / max(min(len(gt), 4.), 1.)
|
||||
|
||||
@staticmethod
|
||||
def bench_one_submit(pred_file, gt_file):
|
||||
print(pred_file,"//////////////////",gt_file)
|
||||
try:
|
||||
json_pred = [json.loads(line) for line in open(pred_file).readlines()]
|
||||
except BaseException as e:
|
||||
raise Exception('Fail to load json file of the prediction.')
|
||||
json_gt = [json.loads(line) for line in open(gt_file).readlines()]
|
||||
print("****************************************",len(json_gt), len(json_pred))
|
||||
if len(json_gt) != len(json_pred):
|
||||
# print(len(json_gt), json_pred)
|
||||
raise Exception('We do not get the predictions of all the test tasks')
|
||||
gts = {l['raw_file']: l for l in json_gt}
|
||||
accuracy, fp, fn = 0., 0., 0.
|
||||
for pred in json_pred:
|
||||
if 'raw_file' not in pred or 'lanes' not in pred or 'run_time' not in pred:
|
||||
raise Exception('raw_file or lanes or run_time not in some predictions.')
|
||||
raw_file = pred['raw_file']
|
||||
pred_lanes = pred['lanes']
|
||||
run_time = pred['run_time']
|
||||
if raw_file not in gts:
|
||||
raise Exception('Some raw_file from your predictions do not exist in the test tasks.')
|
||||
gt = gts[raw_file]
|
||||
gt_lanes = gt['lanes']
|
||||
y_samples = gt['h_samples']
|
||||
try:
|
||||
a, p, n = LaneEval.bench(pred_lanes, gt_lanes, y_samples, run_time)
|
||||
except BaseException as e:
|
||||
raise Exception('Format of lanes error.')
|
||||
# if a <= 0.85:
|
||||
print(raw_file, 'a: ', a)
|
||||
# srcfile = "C:/data/Tusimple/test_set/" + raw_file
|
||||
#fpath, fname = os.path.split(srcfile)
|
||||
#shutil.copy(srcfile, './out/' + fname)
|
||||
accuracy += a
|
||||
fp += p
|
||||
fn += n
|
||||
num = len(gts)
|
||||
# the first return parameter is the default ranking parameter
|
||||
return json.dumps([
|
||||
{'name': 'Accuracy', 'value': accuracy / num, 'order': 'desc'},
|
||||
{'name': 'FP', 'value': fp / num, 'order': 'asc'},
|
||||
{'name': 'FN', 'value': fn / num, 'order': 'asc'}
|
||||
])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
try:
|
||||
if len(sys.argv) != 3:
|
||||
raise Exception('Invalid input arguments')
|
||||
print(LaneEval.bench_one_submit(sys.argv[1], sys.argv[2]))
|
||||
except Exception as e:
|
||||
print(e.message)
|
||||
sys.exit(e.message)
|
||||
102
algorithms/lane_ufld/code.embedded.bak/UFLD/evaluation/tusimple/lane0.py
Executable file
102
algorithms/lane_ufld/code.embedded.bak/UFLD/evaluation/tusimple/lane0.py
Executable file
@@ -0,0 +1,102 @@
|
||||
import numpy as np
|
||||
from sklearn.linear_model import LinearRegression
|
||||
import json
|
||||
|
||||
|
||||
class LaneEval(object):
|
||||
lr = LinearRegression()
|
||||
pixel_thresh = 20
|
||||
pt_thresh = 0.85
|
||||
|
||||
@staticmethod
|
||||
def get_angle(xs, y_samples):
|
||||
xs, ys = xs[xs >= 0], y_samples[xs >= 0]
|
||||
if len(xs) > 1:
|
||||
LaneEval.lr.fit(ys[:, None], xs)
|
||||
k = LaneEval.lr.coef_[0]
|
||||
theta = np.arctan(k)
|
||||
else:
|
||||
theta = 0
|
||||
return theta
|
||||
|
||||
@staticmethod
|
||||
def line_accuracy(pred, gt, thresh):
|
||||
pred = np.array([p if p >= 0 else -100 for p in pred])
|
||||
gt = np.array([g if g >= 0 else -100 for g in gt])
|
||||
return np.sum(np.where(np.abs(pred - gt) < thresh, 1., 0.)) / len(gt)
|
||||
|
||||
@staticmethod
|
||||
def bench(pred, gt, y_samples, running_time):
|
||||
if any(len(p) != len(y_samples) for p in pred):
|
||||
raise Exception('Format of lanes error.')
|
||||
if running_time > 200 or len(gt) + 2 < len(pred):
|
||||
return 0., 0., 1.
|
||||
angles = [LaneEval.get_angle(np.array(x_gts), np.array(y_samples)) for x_gts in gt]
|
||||
threshs = [LaneEval.pixel_thresh / np.cos(angle) for angle in angles]
|
||||
line_accs = []
|
||||
fp, fn = 0., 0.
|
||||
matched = 0.
|
||||
for x_gts, thresh in zip(gt, threshs):
|
||||
accs = [LaneEval.line_accuracy(np.array(x_preds), np.array(x_gts), thresh) for x_preds in pred]
|
||||
max_acc = np.max(accs) if len(accs) > 0 else 0.
|
||||
if max_acc < LaneEval.pt_thresh:
|
||||
fn += 1
|
||||
else:
|
||||
matched += 1
|
||||
line_accs.append(max_acc)
|
||||
fp = len(pred) - matched
|
||||
if len(gt) > 4 and fn > 0:
|
||||
fn -= 1
|
||||
s = sum(line_accs)
|
||||
if len(gt) > 4:
|
||||
s -= min(line_accs)
|
||||
return s / max(min(4.0, len(gt)), 1.), fp / len(pred) if len(pred) > 0 else 0., fn / max(min(len(gt), 4.) , 1.)
|
||||
|
||||
@staticmethod
|
||||
def bench_one_submit(pred_file, gt_file):
|
||||
try:
|
||||
json_pred = [json.loads(line) for line in open(pred_file).readlines()]
|
||||
except BaseException as e:
|
||||
raise Exception('Fail to load json file of the prediction.')
|
||||
json_gt = [json.loads(line) for line in open(gt_file).readlines()]
|
||||
print(len(json_gt), len(json_pred))
|
||||
if len(json_gt) != len(json_pred):
|
||||
raise Exception('We do not get the predictions of all the test tasks')
|
||||
gts = {l['raw_file']: l for l in json_gt}
|
||||
accuracy, fp, fn = 0., 0., 0.
|
||||
for pred in json_pred:
|
||||
if 'raw_file' not in pred or 'lanes' not in pred or 'run_time' not in pred:
|
||||
raise Exception('raw_file or lanes or run_time not in some predictions.')
|
||||
raw_file = pred['raw_file']
|
||||
pred_lanes = pred['lanes']
|
||||
run_time = pred['run_time']
|
||||
if raw_file not in gts:
|
||||
raise Exception('Some raw_file from your predictions do not exist in the test tasks.')
|
||||
gt = gts[raw_file]
|
||||
gt_lanes = gt['lanes']
|
||||
y_samples = gt['h_samples']
|
||||
try:
|
||||
a, p, n = LaneEval.bench(pred_lanes, gt_lanes, y_samples, run_time)
|
||||
except BaseException as e:
|
||||
raise Exception('Format of lanes error.')
|
||||
accuracy += a
|
||||
fp += p
|
||||
fn += n
|
||||
num = len(gts)
|
||||
# the first return parameter is the default ranking parameter
|
||||
return json.dumps([
|
||||
{'name': 'Accuracy', 'value': accuracy / num, 'order': 'desc'},
|
||||
{'name': 'FP', 'value': fp / num, 'order': 'asc'},
|
||||
{'name': 'FN', 'value': fn / num, 'order': 'asc'}
|
||||
])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
try:
|
||||
if len(sys.argv) != 3:
|
||||
raise Exception('Invalid input arguments')
|
||||
print(LaneEval.bench_one_submit(sys.argv[1], sys.argv[2]))
|
||||
except Exception as e:
|
||||
print(e.message)
|
||||
sys.exit(e.message)
|
||||
Reference in New Issue
Block a user