Def init_params (net) :
"' Init layer parameters." '
The for m in.net modules () :
If isinstance (m, nn. Conv2d) :
Init. Kaiming_normal (m. eight, mode='fan_out')
If m.b ias:
Init. Constant (m.b ias, 0)
Elif isinstance (m, nn. BatchNorm2d) :
Init. Constant (m. eight, 1)
Init. Constant (m.b ias, 0)
Elif isinstance (m, nn. Linear) :
Init. Normal (m. eight, STD=1 e - 3)
If m.b ias:
Init. Constant (m.b ias, 0)
_, term_width=OS. Popen (' stty size ', 'r'). The read (). The split ()
Term_width=int (term_width)
Print (term_width)
TOTAL_BAR_LENGTH=65.
Last_time=time. Time ()
Begin_time=last_time
An error is as follows:
Traceback (the most recent call last) :
The File "C:/Users/Yang/Desktop/pytorch - cifar - master/utils. Py", line 39, in & lt; module>
_, term_width=OS. Popen (' stty size ', 'r'). The read (). The split ()
ValueError: not enough values to unpack (expected 2, got 0)
The Process finished with exit code 1
CodePudding user response:
The import OS
The import sys
The import time
The import math
The import torch
The import torch. The nn as nn
Import torch. Nn. The init as init
Def get_mean_and_std (dataset) :
"' Compute the mean and STD the value of the dataset. '"'
Dataloader=torch. Utils. Data. Dataloader (dataset, batch_size=1, shuffle=True, num_workers=0)
Mean=torch. Zeros (3)
STD=torch. Zeros (3)
Print ('==& gt; Computing mean and STD.. ')
For inputs, the targets in dataloader:
For I in range (3) :
Mean [I] +=inputs [: I,,,,] the scheme ()
STD [I] +=inputs [: I,,,,] the STD ()
Mean. Div_ (len (dataset))
STD. Div_ (len (dataset))
Return scheme, STD
Def init_params (net) :
"' Init layer parameters." '
The for m in.net modules () :
If isinstance (m, nn. Conv2d) :
Init. Kaiming_normal (m. eight, mode='fan_out')
If m.b ias:
Init. Constant (m.b ias, 0)
Elif isinstance (m, nn. BatchNorm2d) :
Init. Constant (m. eight, 1)
Init. Constant (m.b ias, 0)
Elif isinstance (m, nn. Linear) :
Init. Normal (m. eight, STD=1 e - 3)
If m.b ias:
Init. Constant (m.b ias, 0)
_, term_width=OS. Popen (' stty size ', 'r'). The read (). The split ()
Term_width=int (term_width)
Print (term_width)
TOTAL_BAR_LENGTH=65.
Last_time=time. Time ()
Begin_time=last_time
Def progress_bar (current, total, MSG=None) :
Global last_time, begin_time
If the current==0:
Begin_time=time. Time () # Reset for the new bar.
Cur_len=int (TOTAL_BAR_LENGTH * current/total)
Rest_len=int (TOTAL_BAR_LENGTH - cur_len) - 1
Sys. Stdout. Write (' [')
For I in range (cur_len) :
Sys. Stdout. Write ('=')
Sys. Stdout. Write (' & gt; ')
For I in range (rest_len) :
Sys. Stdout. Write (')
Sys. Stdout. Write ('])
Cur_time=time. Time ()
Step_time=cur_time - last_time
Last_time=cur_time
Tot_time=cur_time - begin_time
L=[]
L.A. ppend (' Step: % s' % format_time (step_time))
L.A. ppend (' | Tot: % s' % format_time (tot_time))
If the MSG:
L.A. ppend (' | '+ MSG)
MSG="'. Join (L)
Sys. Stdout. Write (MSG)
For I in range (term_width - int (TOTAL_BAR_LENGTH) - len (MSG) - 3) :
Sys. Stdout. Write (' ')
# Go back to the center of the bar.
For I in range (term_width - int (TOTAL_BAR_LENGTH/2) + 2) :
Sys. Stdout. Write (' \ b)
Sys. Stdout. Write ('/% d % d % (+ 1, the current total))
If the current & lt; Total 1:
Sys. Stdout. Write (' \ r ')
The else:
Sys. Stdout. Write (' \ n ')
Sys. Stdout. Flush ()
Def format_time (seconds) :
Days=int (seconds/3600/24)
Seconds=3600 seconds - days * * 24
Hours=int (seconds/3600)
Seconds=seconds - hours * 3600
Minutes=int (60 seconds/)
Seconds=60 seconds - minutes *
Secondsf=int (seconds)
Seconds=seconds - secondsf
Millis=int (seconds * 1000)
F='
I=1
If days & gt; 0:
F +=STR (days) + 'D'
I +=1
If hours & gt; 0 and I & lt;=2:
F +=STR (hours) + 'h'
I +=1
If you & gt; 0 and I & lt;=2:
F +=STR (minutes) + 'm'
I +=1
If secondsf & gt; 0 and I & lt;=2:
F +=STR (secondsf) + 's'
I +=1
If millis & gt; 0 and I & lt;=2:
F +=STR (millis) + 'ms'
I +=1
If f==":
F='0 ms'
Return f
All the code
CodePudding user response:
CodePudding user response:
Print (OS. Popen (' stty size ', 'r'). The read ())Look at what the output should be empty, so couldn't split the two values,
CodePudding user response:
The original poster is run on Windows or Linux, please run ahCodePudding user response:
The building Lord, I have the same problem, can you tell me you solved?