我想帮助理解我所做的事情/为什么我的代码没有像我期望的那样运行.
我已经开始使用joblib来尝试通过并行运行(大)循环来加速我的代码.
我这样使用它:
from joblib import Parallel, delayed
def frame(indeces, image_pad, m):
XY_Patches = np.float32(image_pad[indeces[0]:indeces[0]+m, indeces[1]:indeces[1]+m, indeces[2]])
XZ_Patches = np.float32(image_pad[indeces[0]:indeces[0]+m, indeces[1], indeces[2]:indeces[2]+m])
YZ_Patches = np.float32(image_pad[indeces[0], indeces[1]:indeces[1]+m, indeces[2]:indeces[2]+m])
return XY_Patches, XZ_Patches, YZ_Patches
def Patch_triplanar_para(image_path, patch_size):
Image, Label, indeces = Sampling(image_path)
n = (patch_size -1)/2
m = patch_size
image_pad = np.pad(Image, pad_width=n, mode='constant', constant_values = 0)
A = Parallel(n_jobs= 1)(delayed(frame)(i, image_pad, m) for i in indeces)
A = np.array(A)
Label = np.float32(Label.reshape(len(Label), 1))
R, T, Y = np.hsplit(A, 3)
return R, T, …Run Code Online (Sandbox Code Playgroud) 我已使用 mmdnn 将两个模型(vgg16 和 resnet50)从带有 TensorFlow 后端(来自 model.save 文件)的 Keras 转换为 PyTorch。这是通过以下方式完成的:
mmconvert -sf keras -iw vgg.h5 -df pytorch -om keras_to_torch.pt
A = imp.load_source('MainModel','/weights/keras_to_torch.py')
model = torch.load('/weights/keras_to_torch.pt')
Run Code Online (Sandbox Code Playgroud)
对同一数据集的预测给了我一组不同的结果,因此我进一步调查。
我可以看到所有卷积层的权重都是相同的(转置后),但是最后全连接层的权重却不同。
这应该是有原因的吗?据我了解它们应该是等价的
我正在使用 seaborn 绘制两个子图,如下所示:
fig, (ax1, ax2) = plt.subplots(ncols=2, sharey=True)
sns.swarmplot(flowers[0], flowers[1], hue=colours, ax=ax1)
ax1.set(xlabel='Sepal Length', ylabel='Sepal Width')
plt.legend(loc="upper left", bbox_to_anchor=(1, 1))
sns.swarmplot(flowers[2], flowers[3], hue=colours, ax=ax2)
ax2.set(xlabel='Petal Length', ylabel='Petal Width')
sns.plt.show()
Run Code Online (Sandbox Code Playgroud)
但是,每个子情节都有自己的由颜色决定的图例。是否可以删除其中之一,最好将剩余的放在地块之外?我试过使用,ax1.legend_.remove()但没有用。
我试图用我的数据帧在seaborn中创建一个堆积的条形图.
我首先在pandas中生成了一个交叉表,如下所示:
pd.crosstab(df['Period'], df['Mark'])
Run Code Online (Sandbox Code Playgroud)
返回:
Mark False True
Period BASELINE 583 132
WEEK 12 721 0
WEEK 24 589 132
WEEK 4 721 0
Run Code Online (Sandbox Code Playgroud)
我想使用seaborn来创建一个堆积的条形图以保持一致,这就是我用于其余图形的内容.我一直在努力做到这一点,因为我无法索引交叉表.
我已经能够在大熊猫中使用我想要的情节,.plot.barh(stacked=True)但是没有运气与seaborn.我有什么想法可以做到这一点?
谢谢
我正在尝试使用seaborn生成热图,但是我的数据格式存在一个小问题。
目前,我的数据格式为:
Name Diag Date
A 1 2006-12-01
A 1 1994-02-12
A 2 2001-07-23
B 2 1999-09-12
B 1 2016-10-12
C 3 2010-01-20
C 2 1998-08-20
Run Code Online (Sandbox Code Playgroud)
我想创建一个热图(最好在python中)显示Name在一个轴上Diag-如果发生。我尝试使用旋转数据表pd.pivot,但是出现了错误
ValueError:索引包含重复的条目,无法重塑
来自:
piv = df.pivot_table(index ='Name',columns ='Diag')
时间无关紧要,但是我想展示哪个Names具有哪个Diag,哪个Diag组合聚集在一起。我是否需要为此创建一个新表?在某些情况下,Name并非与所有Diag
编辑:我从此尝试过:piv = df.pivot_table(index ='Name',columns ='Diag',values ='Time',aggfunc ='mean')
但是,由于时间采用日期时间格式,因此我最终得到:
pandas.core.base.DataError:没有要聚合的数字类型