Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
P
prenet
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lishen
prenet
Commits
8ff46ec6
Commit
8ff46ec6
authored
Jul 25, 2022
by
Liuyuxinict
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update725
parent
23172c05
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
0 additions
and
208 deletions
+0
-208
1.py
1.py
+0
-45
Method.png
Method.png
+0
-0
visualization.py
visualization.py
+0
-163
No files found.
1.py
deleted
100644 → 0
View file @
23172c05
import
numpy
as
np
'''
A= np.array([[1,1,1,1,1,1,1,1,1,1,1],
[-5,-4,-3,-2,-1,0,1,2,3,4,5],
]).transpose()
b= np.array([2,7,9,12,13,14,14,13,10,8,4])
AA = np.dot(A.transpose(),A)
print(AA)
AB = np.dot(A.transpose(),b)
print(AB)
x = np.dot(np.linalg.inv(AA),AB)
print(x)
print(np.dot(b-np.dot(A,x),(b-np.dot(A,x).transpose())))
#[25, 16, 9, 4, 1, 0, 1, 4, 9, 16, 25]
A = np.array([[1,3,1,-4],
[-1,-3,1,0],
[2,6,2,-8]])
AA = np.dot(A.transpose(),A)
print(AA)
print(np.linalg.matrix_rank(A))
'''
import
matplotlib.pyplot
as
plt
import
numpy
as
np
plt
.
rcParams
[
'font.sans-serif'
]
=
[
'SimHei'
]
plt
.
rcParams
[
'axes.unicode_minus'
]
=
False
x
=
np
.
random
.
rand
(
10000
)
t
=
np
.
arange
(
len
(
x
))
# plt.plot(t, x, 'g.', label=u'均匀分布') # 散点图
plt
.
hist
(
x
,
1000
,
color
=
'm'
,
alpha
=
0.6
,
label
=
u'均匀分布'
,
normed
=
True
)
plt
.
legend
(
loc
=
'upper right'
)
plt
.
grid
(
True
,
ls
=
':'
)
plt
.
show
()
Method.png
0 → 100644
View file @
8ff46ec6
270 KB
visualization.py
deleted
100644 → 0
View file @
23172c05
import
torch
import
torch.nn
as
nn
import
torch.optim
as
optim
import
cv2
import
numpy
as
np
import
torchvision
from
torchvision
import
datasets
# coding: utf-8
from
PIL
import
Image
from
torch.utils.data
import
Dataset
from
torchvision
import
transforms
from
utils
import
load_model
check
=
False
load_pretrained
=
False
#model = ResNet_aac(fb=64, n_label = 11, model_size=152,kernel_size=3,stride=2,dk=1,dv=1, Nh=8,shape=224,relative = False)
model
=
load_model
(
'resnet50_pmg'
,
pretrain
=
False
,
require_grad
=
True
,
num_class
=
101
)
model
.
cuda
()
model
=
nn
.
DataParallel
(
model
)
#model = resnet152()
pointlist
=
[]
if
load_pretrained
:
model_dict
=
model
.
state_dict
()
#pretrained_dict = torch.load(args.pretrainedmodel)
pretrained_dict
=
torch
.
load
(
"D:/resnet50.pth"
)
# pretrained_dict = model_zoo.load_url('https://download.pytorch.org/models/resnet50-19c8e357.pth')
state_dict
=
{}
for
k
,
v
in
model_dict
.
items
():
# if k in dict1.keys():
if
k
in
pretrained_dict
.
keys
()
and
"fc"
not
in
k
:
#state_dict[k] = pretrained_dict[dict1[k]]
state_dict
[
k
]
=
pretrained_dict
[
k
]
else
:
state_dict
[
k
]
=
v
print
(
k
)
if
check
:
#filename = "best_model_"
#checkpoint = torch.load('./checkpoint/' + filename + 'ckpt.t7')
#checkpoint = torch.load('unprebest.t7')
model
.
module
.
load_state_dict
(
torch
.
load
(
"./food101/model.pth"
)
.
module
.
state_dict
())
model
.
eval
()
test_img
=
"G:/images/apple_pie/116697.jpg"
img
=
Image
.
open
(
test_img
)
.
convert
(
'RGB'
)
transform_test
=
transforms
.
Compose
([
transforms
.
Resize
(
size
=
(
299
,
299
)),
transforms
.
CenterCrop
((
224
,
224
)),
transforms
.
ToTensor
(),
transforms
.
Normalize
((
0.5457954
,
0.44430383
,
0.34424934
),
(
0.23273608
,
0.24383051
,
0.24237761
))
])
img1
=
transform_test
(
img
)
.
reshape
([
1
,
3
,
224
,
224
])
model
(
img1
,
True
)
#print(model(img1,True).shape)
def
on_EVENT_LBUTTONDOWN
(
event
,
x
,
y
,
flags
,
param
):
if
event
==
cv2
.
EVENT_LBUTTONDOWN
:
xy
=
"
%
d,
%
d"
%
(
x
,
y
)
print
(
xy
)
pointlist
.
append
((
x
,
y
))
cv2
.
circle
(
img
,
(
x
,
y
),
1
,
(
255
,
0
,
0
),
thickness
=
-
1
)
cv2
.
putText
(
img
,
xy
,
(
x
,
y
),
cv2
.
FONT_HERSHEY_PLAIN
,
1.0
,
(
0
,
0
,
0
),
thickness
=
1
)
cv2
.
imshow
(
"Image"
,
img
)
return
test_img
=
"G:/images/apple_pie/116697.jpg"
#显示原图
img
=
cv2
.
imread
(
test_img
)
img
=
cv2
.
resize
(
img
,(
224
,
224
))
cv2
.
namedWindow
(
"Image"
)
cv2
.
setMouseCallback
(
"Image"
,
on_EVENT_LBUTTONDOWN
)
img_raw
=
img
.
copy
()
cv2
.
imshow
(
"Image"
,
img
)
cv2
.
waitKey
(
0
)
#显示normalize之后的图
img
=
Image
.
open
(
test_img
)
.
convert
(
'RGB'
)
transform_test
=
transforms
.
Compose
([
transforms
.
Resize
(
size
=
(
224
,
224
)),
transforms
.
ToTensor
(),
transforms
.
Normalize
((
0.5457954
,
0.44430383
,
0.34424934
),
(
0.23273608
,
0.24383051
,
0.24237761
))
])
img1
=
transform_test
(
img
)
img
=
img1
.
transpose
(
0
,
1
)
.
transpose
(
1
,
2
)
img
=
img
.
numpy
()
img
=
cv2
.
cvtColor
(
img
,
cv2
.
COLOR_RGB2BGR
)
cv2
.
imshow
(
"Image"
,
img
)
cv2
.
waitKey
(
0
)
#显示热力图
AAC_mat
=
np
.
load
(
r"D:\PMG\visual\matrix14.npy"
)
depth
=
AAC_mat
.
shape
[
-
1
]
height
=
int
(
np
.
sqrt
(
depth
))
AAC_mat
=
np
.
reshape
(
AAC_mat
,[
8
,
depth
,
depth
])
#print(AAC_mat.shape)
isfirst1
=
True
imgs
=
None
imgs1
=
None
for
item
in
pointlist
:
isfirst
=
True
x
,
y
=
item
x
/=
224
/
height
y
/=
224
/
height
mat
=
AAC_mat
[:,
int
(
x
*
height
+
y
),:]
#print(mat.shape)
#for i in range(0,8):
result
=
mat
result
=
result
.
reshape
([
8
,
height
,
height
])
for
i
in
range
(
0
,
8
):
result
=
mat
[
i
:]
img
=
result
#img = cv2.resize(result, (224, 224))
#img = img*255
heatmap
=
img
/
np
.
max
(
img
)
heatmap
=
np
.
uint8
(
255
*
heatmap
)
w
=
heatmap
w
=
cv2
.
applyColorMap
(
heatmap
,
cv2
.
COLORMAP_JET
)
# 转化为jet 的colormap
#w = heatmap
w
=
cv2
.
resize
(
w
,(
224
,
224
))
#x = img_raw*0.5+w*0.5 # 权重自己定
x
=
w
x
=
x
.
astype
(
np
.
uint8
)
#print(x.shape)
if
isfirst
:
imgs
=
x
isfirst
=
False
else
:
print
(
imgs
.
shape
)
print
(
x
.
shape
)
imgs
=
np
.
hstack
([
imgs
,
x
])
#print(imgs.shape)
if
isfirst1
:
imgs1
=
imgs
isfirst1
=
False
else
:
imgs1
=
np
.
vstack
([
imgs1
,
imgs
])
print
(
imgs1
.
shape
)
cv2
.
imshow
(
"mutil_pic"
,
imgs1
)
cv2
.
waitKey
(
0
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment