@@ -835,6 +835,7 @@ private void CacheFeaturizedImagesToDisk(IDataView input, string labelColumnName
835
835
metrics . Bottleneck . DatasetUsed = dataset ;
836
836
while ( cursor . MoveNext ( ) )
837
837
{
838
+ CheckAlive ( ) ;
838
839
labelGetter ( ref label ) ;
839
840
imageGetter ( ref image ) ;
840
841
if ( image . Length <= 0 )
@@ -888,6 +889,7 @@ private void CreateFeaturizedCacheFile(string cacheFilePath, int examples, int f
888
889
889
890
foreach ( var row in featurizedImages )
890
891
{
892
+ CheckAlive ( ) ;
891
893
writer . WriteLine ( row . Item1 + "," + string . Join ( "," , row . Item2 ) ) ;
892
894
labels [ 0 ] = row . Item1 ;
893
895
for ( int index = 0 ; index < sizeof ( long ) ; index ++ )
@@ -992,6 +994,7 @@ private void TrainAndEvaluateClassificationLayer(string trainBottleneckFilePath,
992
994
993
995
for ( int epoch = 0 ; epoch < epochs ; epoch += 1 )
994
996
{
997
+ CheckAlive ( ) ;
995
998
// Train.
996
999
TrainAndEvaluateClassificationLayerCore ( epoch , learningRate , featureFileStartOffset ,
997
1000
metrics , labelTensorShape , featureTensorShape , batchSize ,
@@ -1119,6 +1122,19 @@ private void TrainAndEvaluateClassificationLayerCore(int epoch, float learningRa
1119
1122
}
1120
1123
}
1121
1124
1125
+ private void CheckAlive ( )
1126
+ {
1127
+ try
1128
+ {
1129
+ Host . CheckAlive ( ) ;
1130
+ }
1131
+ catch ( OperationCanceledException )
1132
+ {
1133
+ TryCleanupTemporaryWorkspace ( ) ;
1134
+ throw ;
1135
+ }
1136
+ }
1137
+
1122
1138
private void TryCleanupTemporaryWorkspace ( )
1123
1139
{
1124
1140
if ( _cleanupWorkspace && Directory . Exists ( _options . WorkspacePath ) )
0 commit comments